diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
commit | 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch) | |
tree | 4464880c571602d54f6ae114729bf62a89518057 /pkg/dataio/cardimage | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'pkg/dataio/cardimage')
-rw-r--r-- | pkg/dataio/cardimage/conversion.x | 221 | ||||
-rw-r--r-- | pkg/dataio/cardimage/mkpkg | 13 | ||||
-rw-r--r-- | pkg/dataio/cardimage/rcardimage.com | 10 | ||||
-rw-r--r-- | pkg/dataio/cardimage/structure.hlp | 139 | ||||
-rw-r--r-- | pkg/dataio/cardimage/t_rcardimage.x | 271 | ||||
-rw-r--r-- | pkg/dataio/cardimage/t_wcardimage.x | 256 | ||||
-rw-r--r-- | pkg/dataio/cardimage/tabs.x | 67 | ||||
-rw-r--r-- | pkg/dataio/cardimage/wcardimage.com | 8 |
8 files changed, 985 insertions, 0 deletions
diff --git a/pkg/dataio/cardimage/conversion.x b/pkg/dataio/cardimage/conversion.x new file mode 100644 index 00000000..0d6f78af --- /dev/null +++ b/pkg/dataio/cardimage/conversion.x @@ -0,0 +1,221 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +define MAX_CHARS 256 + + +# ASCII_TO_EBCDIC -- Vector procedure to convert ASCII characters to EBCDIC +# characters using the lookup table atoe. + +procedure ascii_to_ebcdic (inbuffer, outbuffer, nchars) + +char inbuffer[ARB] +short outbuffer[ARB], atoe[MAX_CHARS] +int l, nchars + +data (atoe[l], l = 1, 8) / 0b, 1b, 2b, 3b, '7' , '-' , '.' , '/' / +data (atoe[l], l = 9, 16) /26b, 5b, '%' , 13b, 14b, 15b, 16b, 17b / +data (atoe[l], l = 17, 24) /20b, 21b, 22b, 23b, '<' , '=' , '2' , '&' / +data (atoe[l], l = 25, 32) /30b, 31b, '?' , '\'', 34b, 35b, 36b, 37b / +data (atoe[l], l = 33, 40) /'@' , 'O' , 177b, '{' , '[' , 'l' , 'P' , '}' / +data (atoe[l], l = 41, 48) /'M' , ']' , '\\' , 'N' , 'k' , '`' , 'K' , 'a'/ +data (atoe[l], l = 49, 56) /360b, 361b, 362b, 363b, 364b, 365b, 366b, 367b/ +data (atoe[l], l = 57, 64) /370b, 371b, 'z' , '^' , 'L' , '~' , 'n' , 'o' / +data (atoe[l], l = 65, 72) /'|' , 301b, 302b, 303b, 304b, 305b, 306b, 307b/ +data (atoe[l], l = 73, 80) /310b, 311b, 321b, 322b, 323b, 324b, 325b, 326b/ +data (atoe[l], l = 81, 88) /327b, 330b, 331b, 342b, 343b, 344b, 345b, 346b/ +data (atoe[l], l = 89, 96) /347b, 350b, 351b, 'J' , 340b, 'Z' , '_' , 'm' / +data (atoe[l], l = 97, 104) /'y' , 201b, 202b, 203b, 204b, 205b, 206b, 207b/ +data (atoe[l], l = 105, 112) /210b, 211b, 221b, 222b, 223b, 224b, 225b, 226b/ +data (atoe[l], l = 113, 120) /227b, 230b, 231b, 242b, 243b, 244b, 245b, 246b/ +data (atoe[l], l = 121, 128) /247b, 250b, 251b, 300b, 'j' , 320b, 241b, 7b/ +data (atoe[l], l = 129, 136) /' ' , '!' , '"' , '#' , '$' , 25b, 6b, 27b/ +data (atoe[l], l = 137, 144) /'(' , ')' , '*' , '+' , ',' , 11b, 12b, 33b/ +data (atoe[l], l = 145, 152) /'0' , '1' , 32b, '3' , '4' , '5' , '6' , 10b/ +data (atoe[l], l = 153, 160) /'8' , '9' , ':' , ';' , 4b, 24b, '>' , 341b/ +data (atoe[l], l = 161, 168) /'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' / +data (atoe[l], l = 169, 176) /'I' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' / +data (atoe[l], l = 177, 184) /'X' , 'Y' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' / +data (atoe[l], l = 185, 192) /'h' , 'i' , 'p' , 'q' , 'r' , 's' , 't' , 'u' / +data (atoe[l], l = 193, 200) /'v' , 'w' , 'x' , 200b, 212b, 213b, 214b, 215b/ +data (atoe[l], l = 201, 208) /216b, 217b, 220b, 232b, 233b, 234b, 235b, 236b/ +data (atoe[l], l = 209, 216) /237b, 240b, 252b, 253b, 254b, 255b, 256b, 257b/ +data (atoe[l], l = 217, 224) /260b, 261b, 262b, 263b, 264b, 265b, 266b, 267b/ +data (atoe[l], l = 225, 232) /270b, 271b, 272b, 273b, 274b, 275b, 276b, 277b/ +data (atoe[l], l = 233, 240) /312b, 313b, 314b, 315b, 316b, 317b, 332b, 333b/ +data (atoe[l], l = 241, 248) /334b, 335b, 336b, 337b, 352b, 353b, 354b, 355b/ +data (atoe[l], l = 249, 256) /356b, 357b, 372b, 373b, 374b, 375b, 376b, 377b/ + +begin + call alutcs (inbuffer, outbuffer, nchars, atoe) +end + + +# EBCDIC_TO_ASCII -- Vector procedure to convert EBCDIC characters to ASCII +# characters. + +procedure ebcdic_to_ascii (inbuffer, outbuffer, nchars) + +char outbuffer[ARB] +short inbuffer[ARB], etoa[MAX_CHARS] +int l, nchars + +data (etoa[l], l = 1, 8) / 0b, 1b, 2b, 3b, 234b, 11b, 206b, 177b / +data (etoa[l], l = 9, 16) /227b, 215b, 216b, 13b, 14b, 15b, 16b, 17b/ +data (etoa[l], l = 17, 24) /20b, 21b, 22b, 23b, 235b, 205b, 10b, 207b / +data (etoa[l], l = 25, 32) /30b, 31b, 222b, 217b, 34b, 35b, 36b, 37b / +data (etoa[l], l = 33, 40) /200b, 201b, 202b, 203b, 204b, 12b, 27b, 33b/ +data (etoa[l], l = 41, 48) /210b, 211b, 212b, 213b, 214b, 5b, 6b, 7b/ +data (etoa[l], l = 49, 56) /220b, 221b, 26b, 223b, 224b, 225b, 226b, 4b/ +data (etoa[l], l = 57, 64) /230b, 231b, 232b, 233b, 24b, 25b, 236b, 32b/ +data (etoa[l], l = 65, 72) /' ' , 240b, 241b, 242b, 243b, 244b, 245b, 246b/ +data (etoa[l], l = 73, 80) /247b, 250b, '[' , '.' , '<' , '(' , '+' , '!' / +data (etoa[l], l = 81, 88) /'&' , 251b, 252b, 253b, 254b, 255b, 256b, 257b/ +data (etoa[l], l = 89, 96) /260b, 261b, ']' , '$' , '*' , ')' , ';' , '^' / +data (etoa[l], l = 97, 104) /'-' , '/' , 262b, 263b, 264b, 265b, 266b, 267b/ +data (etoa[l], l = 105, 112) /270b, 271b, '|' , ',' , '%' , '_' , '>' , '?' / +data (etoa[l], l = 113, 120) /272b, 273b, 274b, 275b, 276b, 277b, 300b, 301b/ +data (etoa[l], l = 121, 128) /302b, '`' , ':' , '#' , '@' , '\'' , '=' , '"'/ +data (etoa[l], l = 129, 136) /303b, 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' / +data (etoa[l], l = 137, 144) /'h' , 'i' , 304b, 305b, 306b, 307b, 310b, 311b/ +data (etoa[l], l = 145, 152) /312b, 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' / +data (etoa[l], l = 153, 160) /'q' , 'r' , 313b, 314b, 315b, 316b, 317b, 320b/ +data (etoa[l], l = 161, 168) /321b, '~' , 's' , 't' , 'u' , 'v' , 'w' , 'x' / +data (etoa[l], l = 169, 176) /'y' , 'z' , 322b, 323b, 324b, 325b, 326b, 327b/ +data (etoa[l], l = 177, 184) /330b, 331b, 332b, 333b, 334b, 335b, 336b, 337b/ +data (etoa[l], l = 185, 192) /340b, 341b, 342b, 343b, 344b, 345b, 346b, 347b/ +data (etoa[l], l = 193, 200) /'{' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' / +data (etoa[l], l = 201, 208) /'H' , 'I' , 350b, 351b, 352b, 353b, 354b, 355b/ +data (etoa[l], l = 209, 216) /'}' , 'J' , 'K' , 'L' , 'M' , 'N' , 'O' , 'P' / +data (etoa[l], l = 217, 224) /'Q' , 'R' , 356b, 357b, 360b, 361b, 362b, 363b/ +data (etoa[l], l = 225, 232) /'\\', 237b, 'S' , 'T' , 'U' , 'V' , 'W' , 'X' / +data (etoa[l], l = 233, 240) /'Y' , 'Z' , 364b, 365b, 366b, 367b, 370b, 371b/ +data (etoa[l], l = 241, 248) /'0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' / +data (etoa[l], l = 249, 256) /'8' , '9' , 372b, 373b, 374b, 375b, 376b, 377b/ + +begin + call alutsc (inbuffer, outbuffer, nchars, etoa) +end + + +# IBM_TO_ASCII -- Vector procedure for converting IBM characters to ASCII +# characters. + +procedure ibm_to_ascii (inbuffer, outbuffer, nchars) + +char outbuffer[ARB] +short inbuffer[ARB], ibmtoa[MAX_CHARS] +int l, nchars + +data (ibmtoa[l], l = 1, 8) /0b, 1b, 2b, 3b, 234b, 11b, 206b, 177b / +data (ibmtoa[l], l = 9, 16) /1227b, 215b, 216b, 13b, 14b, 15b, 16b, 17b/ +data (ibmtoa[l], l = 17, 24) /20b, 21b, 22b, 23b, 235b, 205b, 10b, 207b / +data (ibmtoa[l], l = 25, 32) /30b, 31b, 222b, 217b, 34b, 35b, 36b, 37b / +data (ibmtoa[l], l = 33, 40) /200b, 201b, 202b, 203b, 204b, 12b, 27b, 33b/ +data (ibmtoa[l], l = 41, 48) /210b, 211b, 212b, 213b, 214b, 5b, 6b, 7b/ +data (ibmtoa[l], l = 49, 56) /220b, 221b, 26b, 223b, 224b, 225b, 226b, 4b/ +data (ibmtoa[l], l = 57, 64) /230b, 231b, 232b, 233b, 24b, 25b, 236b, 32b/ +data (ibmtoa[l], l = 65, 72) /' ' , 240b, 241b, 242b, 243b, 244b, 245b, 246b/ +data (ibmtoa[l], l = 73, 80) /247b, 250b, 0b, '.' , '<' , '(' , '+' , '|' / +data (ibmtoa[l], l = 81, 88) /'&' , 251b, 252b, 253b, 254b, 255b, 256b, 257b/ +data (ibmtoa[l], l = 89, 96) /260b, 261b, '!' , '$' , '*' , ')' , ';' , '^' / +data (ibmtoa[l], l = 97, 104) /'-' , '/' , 262b, 263b, 264b, 265b, 266b, 267b/ +data (ibmtoa[l], l = 105,112) /270b, 271b, 0b, ',' , '%' , '_' , '>' , '?' / +data (ibmtoa[l], l = 113, 120) /272b, 273b, 274b, 275b, 276b, 277b, 300b, 301b/ +data (ibmtoa[l], l = 121, 128) /302b, '`' , ':' , '#' , '@' , '\'' , '=' , '"'/ +data (ibmtoa[l], l = 129, 136) /303b, 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' / +data (ibmtoa[l], l = 137, 144) /'h' , 'i' , 304b, 305b, 306b, 307b, 310b, 311b/ +data (ibmtoa[l], l = 145, 152) /312b, 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' / +data (ibmtoa[l], l = 153, 160) /'q' , 'r' , 313b, 314b, 315b, 316b, 317b, 320b/ +data (ibmtoa[l], l = 161, 168) /321b, '~' , 's' , 't' , 'u' , 'v' , 'w' , 'x' / +data (ibmtoa[l], l = 169, 176) /'y' , 'z' , 322b, 323b, 324b, 325b, 326b, 327b/ +data (ibmtoa[l], l = 177, 184) /330b, 331b, 332b, 333b, 334b, 335b, 336b, 337b/ +data (ibmtoa[l], l = 185, 192) /340b, 341b, 342b, 343b, 344b, 345b, 346b, 347b/ +data (ibmtoa[l], l = 193, 200) /'{' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' / +data (ibmtoa[l], l = 201, 208) /'H' , 'I' , 350b, 351b, 352b, 353b, 354b, 355b/ +data (ibmtoa[l], l = 209, 216) /'}' , 'J' , 'K' , 'L' , 'M' , 'N' , 'O' , 'P' / +data (ibmtoa[l], l = 217, 224) /'Q' , 'R' , 356b, 357b, 360b, 361b, 362b, 363b/ +data (ibmtoa[l], l = 225, 232) /'\\', 237b, 'S' , 'T' , 'U' , 'V' , 'W' , 'X' / +data (ibmtoa[l], l = 233, 240) /'Y' , 'Z' , 364b, 365b, 366b, 367b, 370b, 371b/ +data (ibmtoa[l], l = 241, 248) /'0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' / +data (ibmtoa[l], l = 249, 256) /'8' , '9' , 372b, 373b, 374b, 375b, 376b, 377b / + +begin + call alutsc (inbuffer, outbuffer, nchars, ibmtoa) +end + + +# ASCII_TO_IBM -- Vector procedure to convert ASCII characters to IBM +# characters. + +procedure ascii_to_ibm (inbuffer, outbuffer, nchars) + +char inbuffer[ARB] +short outbuffer[ARB], atoibm[MAX_CHARS] +int l, nchars + +data (atoibm[l], l = 1, 8) /0b, 1b, 2b, 3b, '7' , '-' , '.' , '/' / +data (atoibm[l], l = 9, 16) /26b, 5b, '%' , 13b, 14b, 15b, 16b, 17b / +data (atoibm[l], l = 17, 24) /20b, 21b, 22b, 23b, '<' , '=' , '2' , '&' / +data (atoibm[l], l = 25, 32) /30b, 31b, '?' , '\'', 34b, 35b, 36b, 37b / +data (atoibm[l], l = 33, 40) /'@' , 'Z' , 177b, '{' , '[' , 'l' , 'P' , '}' / +data (atoibm[l], l = 41, 48) /'M' , ']' , '\\', 'N' , 'k' , '`' , 'K' , 'a' / +data (atoibm[l], l = 49, 56) /360b, 361b, 362b, 363b, 364b, 365b, 366b, 367b/ +data (atoibm[l], l = 57, 64) /370b, 371b, 'z' , '^' , 'L' , '~' , 'n' , 'o' / +data (atoibm[l], l = 65, 72) /'|' , 301b, 302b, 303b, 304b, 305b, 306b, 307b/ +data (atoibm[l], l = 73, 80) /310b, 311b, 321b, 322b, 323b, 324b, 325b, 326b/ +data (atoibm[l], l = 81, 88) /327b, 330b, 331b, 342b, 343b, 344b, 345b, 346b/ +data (atoibm[l], l = 89, 96) /347b, 350b, 351b, 255b, 340b, 275b, '_' , 'm' / +data (atoibm[l], l = 97, 104) /'y' , 201b, 202b, 203b, 204b, 205b, 206b, 207b/ +data (atoibm[l], l = 105, 112) /210b, 211b, 221b, 222b, 223b, 224b, 225b, 226b/ +data (atoibm[l], l = 113, 120) /227b, 230b, 231b, 242b, 243b, 244b, 245b, 246b/ +data (atoibm[l], l = 121, 128) /247b, 250b, 251b, 300b, 'O' , 320b, 241b, 7b/ +data (atoibm[l], l = 129, 136) /' ' , '!' , '"' , '#' , '$' , 25b, 6b, 27b/ +data (atoibm[l], l = 137, 144) /'(' , ')' , '*' , '+' , ',' , 11b, 12b, 33b/ +data (atoibm[l], l = 145, 152) /'0' , '1' , 32b, '3' , '4' , '5' , '6' , 10b/ +data (atoibm[l], l = 153, 160) /'8' , '9' , ':' , ';' , 4b, 24b, '>' , 341b/ +data (atoibm[l], l = 161, 168) /'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' / +data (atoibm[l], l = 169, 176) /'I' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' / +data (atoibm[l], l = 177, 184) /'X' , 'Y' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' / +data (atoibm[l], l = 185, 192) /'h' , 'i' , 'p' , 'q' , 'r' , 's' , 't' , 'u' / +data (atoibm[l], l = 193, 200) /'v' , 'w' , 'x' , 200b, 212b, 213b, 214b, 215b/ +data (atoibm[l], l = 201, 208) /216b, 217b, 220b, 232b, 233b, 234b, 235b, 236b/ +data (atoibm[l], l = 209, 216) /237b, 240b, 252b, 253b, 254b, 255b, 256b, 257b/ +data (atoibm[l], l = 217, 224) /260b, 261b, 262b, 263b, 264b, 265b, 266b, 267b/ +data (atoibm[l], l = 225, 232) /270b, 271b, 272b, 273b, 274b, 275b, 276b, 277b/ +data (atoibm[l], l = 233, 240) /312b, 313b, 314b, 315b, 316b, 317b, 332b, 333b/ +data (atoibm[l], l = 241, 248) /334b, 335b, 336b, 337b, 352b, 353b, 354b, 355b/ +data (atoibm[l], l = 249, 256) /356b, 357b, 372b, 373b, 374b, 375b, 376b, 377b/ + +begin + call alutcs (inbuffer, outbuffer, nchars, atoibm) +end + + +# ALUTSC -- Vector operator to map one set of characters to another using a +# lookup table. + +procedure alutsc (a, b, nchars, lut) + +char b[nchars] +int nchars, i +short a[nchars], lut[ARB] + +begin + do i = 1, nchars, 1 + b[i] = lut[a[i] + 1] +end + + +# ALUTCS -- Vector operator to map one set of characters to another using +# a lookup table. + +procedure alutcs (a, b, nchars, lut) + +char a[nchars] +int nchars, i +short b[nchars], lut[ARB] + +begin + do i = nchars, 1, -1 + b[i] = lut[a[i] + 1] +end diff --git a/pkg/dataio/cardimage/mkpkg b/pkg/dataio/cardimage/mkpkg new file mode 100644 index 00000000..63e23fc4 --- /dev/null +++ b/pkg/dataio/cardimage/mkpkg @@ -0,0 +1,13 @@ +# Cardimage library + +$checkout libpkg.a ../ +$update libpkg.a +$checkin libpkg.a ../ +$exit + +libpkg.a: + t_rcardimage.x rcardimage.com <error.h> <ctype.h> <mach.h> <fset.h> + t_wcardimage.x wcardimage.com <fset.h> <error.h> <mach.h> + conversion.x + tabs.x + ; diff --git a/pkg/dataio/cardimage/rcardimage.com b/pkg/dataio/cardimage/rcardimage.com new file mode 100644 index 00000000..064f1af3 --- /dev/null +++ b/pkg/dataio/cardimage/rcardimage.com @@ -0,0 +1,10 @@ +int card_length +int max_line_length +int trim +int entab +int ebcdic +int ibm +char contn_string[SZ_LINE] + +common /rcardcom/ card_length, max_line_length, trim, entab, ebcdic, ibm, + contn_string diff --git a/pkg/dataio/cardimage/structure.hlp b/pkg/dataio/cardimage/structure.hlp new file mode 100644 index 00000000..4a8b5622 --- /dev/null +++ b/pkg/dataio/cardimage/structure.hlp @@ -0,0 +1,139 @@ +.help cardimage Jan85 dataio +.sh +RCARDIMAGE Structure Chart + +.nf +t_rcardimage() +# Returns when file list is satisfied or EOT is encountered. + + cardfile_to_textfile (in_fname, out_fname, nlines, ncards) + + fetchcard (fd, outline, ncards) + # Returns number of chars read or EOF + + card_to_text (fd, instring) + # Returns number of chars or EOF + + conversion routines +.fi + +.sh +WCARDIMAGE Structure Chart + +.nf +t_wcardimage() +# Returns when file list is satisfied. + + textfile_to_cardfile (in_file, out_fname, ncards, nlines) + + fetchline (fd, linebuf, nlines) + # Returns EOF or number of chars read + + text_to_card (line, nchars, card) + + conversion routines +.fi +.sh +RCARDIMAGE Structure Summary + +.ls t_rcardimage +The main procedure reads the control parameters. +The files to be read and converted are calculated from the specified source +and file list. A loop trough the files determines the specific input +and output filenames and calls CARDFILE_TO_TEXTFILE for each conversion. +.ls cardfile_to_textfile +The input and output files are opened. Successive card images are fetched and +converted to text lines by FETCHCARD. If the ENTAB switch is enabled +blanks are replaced by tabs and blanks. +.ls fetchcard +This procedure reads individual card images, optionally joining those +images prefixed by an indentifying continuation string with the previous +card image(s). If trim is enabled white space is removed. Newline and +EOS are added. +.ls card_to_text +Converts a packed card image to a text image. Call the CONVERSION routines +to convert from EBCDIC to ASCII if the ebcdic switch is set. +.le +.le +.le +.le +.sh +WCARDIMAGE Structure Summary + +.ls t_wcardimage +The main procedure read the control parameters. +The files to be read and converted are calculated from the specified +source and file list. A loop through the files determines the specific +input source names and output filenames and calls TEXTFILE_TO_CARDFILE +for each conversion. +.ls textfile_to_cardfile +The input and output source files are opened. Successive text lines are +read and converted to one or more lines card_length + 1 long by +calls to FETCHLINE. +.ls fetchline +FETCHLINE fetches lines of text and splits them into pieces <= +maxch characters long optionally prefixing the remainders with +an identifying continuation string. If the detab switch is set +tabs in the lines are replaced with blanks. +.ls text_to_card +Converts a text string into a packed card image removing the newline +character if necessary and padding with blanks if required. +Call the conversion routines to convert from ASCII to EBCDIC if the +ebcdic switch is set. +.le +.le +.le +.le +.sh +MTEXAMINE Structure Chart + +.nf +t_mtexamine () +# Returns when file list is satisfied + + mtexamine (tape_file, dump_range, byte_chunk, field_len, + vals_per_lines, output_format) + # Returns number of records read + + bytupkl (a, b, nbytes, byte_chunk, byteswap) + + dump (ptr, byte_chunk, nelems, field_len, vals_per_line, + output_format, max_plusint, twice_max_plusint) + + sign_convert (a, nelems, max_plusint, twice_max_plusint) +.fi +.sh +MTEXAMINE Structure Summary +.ls t_mtexamine +T_MTEXAMINE fetches the program parameters and calculates the +input file list. If dump_records is yes, T_MTEXAMINE +calculates the record list to be dumped, calculates the field length +and number of values which can be printed on a line and checks to see that the +data_type and output_format parameters are permitted types. For each +file in the input list T_MTEXAMINE calls MTEXAMINE. +.ls mtexamine +If dump_records is no, MTEXAMINE prints the record structure of the specified +files on the standard output. Otherwise MTEXAMINE loops through the tape +records until it reaches a record number in the record list +and calls dump to output the record to +the standard output. +.ls bytupkl +BYTUPKL unpacks unsigned bytes into and integer array, optionally swaps +the bytes, and assembles byte_chunk bytes into a long integer. +.le +.ls dump +DUMP prints the record on the standard output using the specified +output format and data type. If byte_chunk is 1 the output is unsigned. +If byte_chunk is equal to the size in bytes of a long integer, then +the data will be printed as signed. If byte_chunk is greater than one +and less then the length of a long the data will be signed if the +output format is decimal and unsigned otherwise. DUMP calls twos_comp +to do the sign conversion. +.ls sign_convert +SIGN_CONVERT does a twos complement sign conversion if the output format is +decimal and byte_chunk is greater than one and less than the size of a +long integer. +.le +.le +.le +.le diff --git a/pkg/dataio/cardimage/t_rcardimage.x b/pkg/dataio/cardimage/t_rcardimage.x new file mode 100644 index 00000000..a2dad404 --- /dev/null +++ b/pkg/dataio/cardimage/t_rcardimage.x @@ -0,0 +1,271 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <error.h> +include <ctype.h> +include <mach.h> +include <fset.h> + +define MAX_RANGES 100 +define TABSIZE 8 + +# T_RCARDIMAGE -- Procedure to read cardimages tapes. Documentation in +# rcardimage.hlp. + +procedure t_rcardimage() + +char infile[SZ_FNAME] # the input file name list +char outfile[SZ_FNAME] # the output file name list +char file_list[SZ_LINE] # the file number list +int offset # the file number offset +bool join # join long lines ? +bool verbose # verbose output ? + +char in_fname[SZ_FNAME], out_fname[SZ_FNAME] +int nlines, file_number, ncards, range[MAX_RANGES*2+1], nfiles +int lenlist, junk +pointer list + +bool clgetb() +int btoi(), clgeti(), mtfile(), mtneedfileno(), strlen(), decode_ranges() +int get_next_number(), fntlenb(), fntgfnb(), fstati() +pointer fntopnb() +include "rcardimage.com" + +begin + if (fstati (STDOUT, F_REDIR) == NO) + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get parameters. + call clgstr ("cardfile", infile, SZ_FNAME) + call clgstr ("textfile", outfile, SZ_FNAME) + + # Make up a file list. + if (mtfile (infile) == YES) { + list = NULL + if (mtneedfileno (infile) == YES) + call clgstr ("file_list", file_list, SZ_LINE) + else + call strcpy ("1", file_list, SZ_LINE) + } else { + list = fntopnb (infile, YES) + lenlist = fntlenb (list) + call sprintf (file_list, SZ_LINE, "1-%d") + call pargi (lenlist) + } + + # Decode the ranges. + if (decode_ranges (file_list, range, MAX_RANGES, nfiles) == ERR) + call error (1, "Illegal file number list") + + # Set up the formatting parameters. + card_length = min (SZ_LINE, clgeti ("card_length")) + if (mod (card_length, SZB_CHAR) != 0) + call error (2, "A card must contain an even number of characters") + max_line_length = min (SZ_LINE, clgeti ("max_line_length")) + join = clgetb ("join") + if (join) + call clgstr ("contn_string", contn_string, SZ_LINE) + else + contn_string[1] = EOS + entab = btoi (clgetb ("entab")) + trim = btoi (clgetb ("trim")) + ebcdic = btoi (clgetb ("ebcdic")) + ibm = btoi (clgetb ("ibm")) + if (ibm == YES && ebcdic == YES) + call error (3, "Ibm and ebcdic cannot both be true.") + + offset = clgeti ("offset") + verbose = clgetb ("verbose") + + # Read successive cardimage files, convert and write into a numbered + # succession of output textfiles. + + file_number = 0 + while (get_next_number (range, file_number) != EOF) { + + # Get the input file name. + if (list != NULL) + junk = fntgfnb (list, in_fname, SZ_FNAME) + else { + if (mtneedfileno (infile) == YES) + call mtfname (infile, file_number, in_fname, SZ_FNAME) + else + call strcpy (infile, in_fname, SZ_FNAME) + + } + + # Get the output file name. + call strcpy (outfile, out_fname, SZ_FNAME) + if (nfiles > 1) { + call sprintf (out_fname[strlen(out_fname)+1], SZ_FNAME, "%03d") + call pargi (file_number + offset) + } + + # Copy the cardimage file to the output text file. If a read + # error occurs, try next file. If a zero length file is read, + # meaning that EOT was reached prematurely, merely exit, deleting + # the zero length output file. + + iferr { + if (verbose) { + call printf ("File: %s -> %s: ") + call pargstr (in_fname) + call pargstr (out_fname) + } + + call rc_cardfile_to_textfile (in_fname, out_fname, nlines, + ncards) + + if (verbose) { + call printf ("%d card images -> %d text lines\n") + call pargi (ncards) + call pargi (nlines) + } + + } then { + call flush (STDOUT) + call erract (EA_FATAL) + } else if (nlines == 0) { # EOT reached + if (verbose) { + call printf ("EOT encountered at file %s\n") + call pargi (file_number + offset) + } + call delete (out_fname) + break + } + } + + if (list != NULL) + call fntclsb (list) +end + + +# RC_CARDFILE_TO_TEXTFILE -- Copy a cardfile to a new textfile. +# Outputs the number of cards read and lines written. + +procedure rc_cardfile_to_textfile (in_fname, out_fname, nlines, ncards) + +char in_fname[ARB] # the input file name +char out_fname[ARB] # the output file name +int nlines # the number of lines +int ncards # the number of cards + +char lbuf[SZ_LINE], tempbuf[SZ_LINE] +int in, out, nchars +int mtopen(), open(), rc_fetchcard() +errchk mtopen, open, rc_fetchcard, putline, strentab, close +include "rcardimage.com" + +begin + in = mtopen (in_fname, READ_ONLY, 0) + out = open (out_fname, NEW_FILE, TEXT_FILE) + + ncards = 0 + iferr { + nchars = rc_fetchcard (in, lbuf, ncards) + for (nlines = 0; nchars != EOF; nlines = nlines + 1) { + if (entab == YES) { + call strentab (lbuf, tempbuf, max_line_length, TABSIZE) + call putline (out, tempbuf) + } else + call putline (out, lbuf) + nchars = rc_fetchcard (in, lbuf, ncards) + } + } then + call erract (EA_WARN) + + call close (in) + call close (out) +end + + +# RC_FETCHCARD -- Procedure to read card images and join those images prefixed +# by an identifying continuation string with the previous image(s). +# Returns number of characters in line or EOF. + +int procedure rc_fetchcard (fd, outline, cp) + +int fd # the input file descriptor +char outline[ARB] # the output line +int cp # the card counter + +bool newfile +char instring[SZ_LINE * SZ_SHORT] +int ip, op, npacked_chars, strsize +int rc_card_to_text(), strlen(), strncmp() +errchk rc_card_to_text +data newfile/true/ +include "rcardimage.com" + +begin + ip = 1 + op = 1 + strsize = strlen (contn_string) + + # Get first line of file. + if (newfile) { + npacked_chars = rc_card_to_text (fd, instring) + newfile = false + } + + while (npacked_chars != EOF) { + # Count cards and file output buffer. + while (instring[ip] != EOS && op < max_line_length) { + outline[op] = instring[ip] + ip = ip + 1 + op = op + 1 + } + cp = cp + 1 + + # Check for continuation string in next line, move pointer if yes. + npacked_chars = rc_card_to_text (fd, instring) + + if ((strsize != 0) && + (strncmp (instring, contn_string, strsize) == 0) && + (npacked_chars != EOF)) { + ip = strsize + 1 + } else { + # Output line, remove whitespace, add newline and delimit string + if (trim == YES) + while (op >= 2 && IS_WHITE (outline[op-1])) + op = op -1 + outline[op] = '\n' + outline[op+1] = EOS + return (op) + } + } + + # Initialize for new file. + newfile = true + return (EOF) +end + + +# RC_CARD_TO_TEXT -- Procedure to transform a packed card image to a text image. + +int procedure rc_card_to_text (fd, card) + +int fd # input file descriptor +char card[ARB] # the packed/unpacked cardimage image + +int npacked_chars, nchars +int read() +errchk read, ebcdic_to_ascii, ibm_to_ascii +include "rcardimage.com" + +begin + npacked_chars = read (fd, card, card_length/SZB_CHAR) + if (npacked_chars == EOF) + return (EOF) + nchars = npacked_chars * SZB_CHAR + if (ebcdic == YES) { + call achtbs (card, card, nchars) + call ebcdic_to_ascii (card, card, nchars) + } else if (ibm == YES) { + call achtbs (card, card, nchars) + call ibm_to_ascii (card, card, nchars) + } else + call chrupk (card, 1, card, 1, nchars) + card[nchars+1] = EOS + return (nchars) +end diff --git a/pkg/dataio/cardimage/t_wcardimage.x b/pkg/dataio/cardimage/t_wcardimage.x new file mode 100644 index 00000000..0a85bb55 --- /dev/null +++ b/pkg/dataio/cardimage/t_wcardimage.x @@ -0,0 +1,256 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <fset.h> +include <error.h> +include <mach.h> + +define TABSIZE 8 + +# Procedure to write cardimage files. See wcardimage.hlp for documentation. + +procedure t_wcardimage() + +char out_file[SZ_FNAME] # input file name list +char in_file[SZ_FNAME] # output file name list +bool verbose # verbose mode ? + +char out_fname[SZ_FNAME] +int ncards, file_number, nlines, list, len_list + +bool clgetb() +int fstati(), clpopni(), clplen(), mtfile(), mtneedfileno() +int clgeti(), clgfil(), strlen(), btoi() +include "wcardimage.com" + +begin + # Flush standard output on newline + if (fstati (STDOUT, F_REDIR) == NO) + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get the parameters. + list = clpopni ("textfile") + len_list = clplen (list) + + # Get name of output file. + # If no tape file number is given tape output then the program + # asks whether the tape is blank or contains data. + # If it is blank the tape begins writing at file 1 otherwise at EOT. + # Note that at some point this code needs to be modified to + # accept an output file name template. + + call clgstr ( "cardfile", out_file, SZ_FNAME) + if (mtfile (out_file) == YES) { + if (mtneedfileno (out_file) == YES) { + if (! clgetb("new_tape")) + call mtfname (out_file, EOT, out_fname, SZ_FNAME) + else + call mtfname (out_file, 1, out_fname, SZ_FNAME) + } else + call strcpy (out_file, out_fname, SZ_FNAME) + } + + # Get card_length and determine whether it fits in an integral number + # of characters. + + card_length = min (SZ_LINE, clgeti ("card_length")) + if (mod (card_length, SZB_CHAR) != 0) + call error (1, "A card must fit in an integral number of chars.") + + # Get number of cards per physical block and convert to packed chars. + cards_per_blk = clgeti ("cards_per_blk") + + # Get the formatting parameters. + call clgstr ("contn_string", contn_string, SZ_LINE) + if (strlen (contn_string) > card_length) + call error (2, + "Continuation string cannot be > card_length chars.") + detab = btoi (clgetb ("detab")) + + # Get the character type parameters. + ebcdic = btoi (clgetb ("ebcdic")) + ibm = btoi (clgetb ("ibm")) + if (ibm == YES && ebcdic == YES) + call error (3, "Ibm and ebcdic cannot both be true.") + + verbose = clgetb ("verbose") + + file_number = 1 + while (clgfil (list, in_file, SZ_FNAME) != EOF) { + if (mtfile (out_file) == NO) { + if (len_list > 1) { + call sprintf (out_fname[1], SZ_FNAME, "%s%03d") + call pargstr (out_file) + call pargi (file_number) + } else + call strcpy (out_file, out_fname, SZ_FNAME) + } else { + if (file_number == 2) + call mtfname (out_fname, EOT, out_fname, SZ_FNAME) + } + + # Copy text file to cardimage file. + + iferr { + if (verbose) { + call printf ("File: %s -> %s: ") + call pargstr (in_file) + call pargstr (out_fname) + } + + call wc_textfile_to_cardfile (in_file, out_fname, ncards, + nlines) + + if (verbose) { + call printf ("%d lines read -> %d cards written\n") + call pargi (nlines) + call pargi (ncards) + } + } then { + call flush (STDOUT) + call erract (EA_FATAL) + } else if (ncards == 0) { + if (verbose) + call printf ("\tInput file is binary or empty\n") + } + + file_number = file_number + 1 + } +end + + +# WC_TEXTFILE_TO_CARDFILE -- Reads a textfile from disk and outputs a card +# image file to tape or disk. + +procedure wc_textfile_to_cardfile (in_file, out_fname, ncards, nlines) + +char in_file[ARB] # input file name +char out_fname[ARB] # output file name +int ncards # number of card images +int nlines # number of text lines + +char linebuf[SZ_LINE] +int in, out, nchars, chars_per_blk +int mtopen(), open(), access(), wc_fetchline(), mtfile() +errchk mtopen, open, access, wc_fetchline, write, close, wc_text_to_card +include "wcardimage.com" + +begin + nlines = 0 + ncards = 0 + + if (access (in_file, READ_ONLY, TEXT_FILE) != YES) + return + + # Open the file. + in = open (in_file, READ_ONLY, TEXT_FILE) + if (mtfile (out_fname) == YES) { + chars_per_blk = cards_per_blk * card_length / SZB_CHAR + out = mtopen (out_fname, WRITE_ONLY, chars_per_blk) + } else + out = open (out_fname, NEW_FILE, BINARY_FILE) + + # Write file. + nchars = wc_fetchline (in, linebuf, nlines, card_length+1) + while (nchars != EOF) { + call wc_text_to_card (linebuf, nchars, linebuf) + call write (out, linebuf, card_length/SZB_CHAR) + ncards = ncards + 1 + nchars = wc_fetchline (in, linebuf, nlines, card_length+1) + } + + call close (in) + call close (out) +end + + +# WC_TEXT_TO_CARD -- Convert text string into a packed cardimage string +# removing the newline character if necessary, padding with blanks +# if required and optionally translating from ascii to ebcdic or ibm +# ebcdic. + +procedure wc_text_to_card (line, nchars, card) + +char line[ARB] # input text line +int nchars # number of chars in line +char card[ARB] # output packed card image + +int init, ip +errchk ascii_to_ebcdic, ascii_to_ibm, achtsb, chrpak +include "wcardimage.com" + +begin + # Pad with blanks. + init = nchars + if (line[init] != '\n') + init = init + 1 + for (ip=init; ip <= card_length; ip=ip+1) + line[ip] = ' ' + + # Pack the line. + if (ebcdic == YES) { + call ascii_to_ebcdic (line, card, card_length) + call achtsb (card, card, card_length) + } else if (ibm == YES) { + call ascii_to_ibm (line, card, card_length) + call achtsb (card, card, card_length) + } else + call chrpak (line, 1, card, 1, card_length) +end + + +# WC_FETCHLINE -- Procedure to fetch a line of text and split it into pieces +# <= maxch characters long, optionally prefixing the remainders of lines +# with a character string. + +int procedure wc_fetchline (fd, linebuf, lp, maxch) + +int fd # input file descriptor +char linebuf[ARB] # output chunk of text +int lp # number of lines read +int maxch # maximum size of chunk of text + +char line[SZ_LINE], inline[SZ_LINE] +int nchars, ip, op, offset, strsize +int getline(), gstrcpy(), strlen(), strncmp() +errchk getline(), strdetab() +include "wcardimage.com" +data ip /1/ + +begin + # Get new line and detab if requested. + if (ip == 1) { + if (detab == YES) { + nchars = getline (fd, inline) + call strdetab (inline, line, SZ_LINE, TABSIZE) + } else + nchars = getline (fd, line) + if (nchars == EOF) + return (EOF) + + lp = lp + 1 + offset = 0 + strsize = strlen (contn_string) + if (strsize != 0 && strncmp (line, contn_string, strsize) == 0) + call eprintf ("Warning: Line matches continuation string\n") + + } else { + # Otherwise determine length of continuation string. + offset = gstrcpy (contn_string, linebuf, SZ_LINE) + } + + # Copy maxch characters to the output buffer. + op = offset + 1 + while (line[ip] != EOS && op < maxch && line[ip] != '\n') { + linebuf[op] = line[ip] + ip = ip + 1 + op = op + 1 + } + + # Add newline and EOS reset pointer. + linebuf[op] = '\n' + linebuf[op+1] = EOS + if (line[ip] == EOS || line[ip] == '\n') + ip = 1 + + return (op) +end diff --git a/pkg/dataio/cardimage/tabs.x b/pkg/dataio/cardimage/tabs.x new file mode 100644 index 00000000..ccb722a2 --- /dev/null +++ b/pkg/dataio/cardimage/tabs.x @@ -0,0 +1,67 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +# STRDETAB -- Procedure to remove tabs from a line of text and replace with +# blanks. + +procedure strdetab (line, outline, maxch, tabsize) + +int ip, op, maxch, tabsize +char line[ARB], outline [ARB] + +begin + op=1 + ip=1 + + while (line[ip] != EOS && op <= maxch) { + if (line[ip] == '\t') { + repeat { + outline[op] = ' ' + op = op + 1 + } until ((mod (op, tabsize) == 1) || (op > maxch)) + ip = ip + 1 + } else { + outline[op] = line[ip] + op = op + 1 + ip = ip + 1 + } + } + + outline[op] = EOS +end + + +# STRENTAB -- Procedure to replace blanks with tabs and blanks. + +procedure strentab (line, outline, maxch, tabsize) + +int maxch, tabsize +char line[ARB], outline[ARB] +int ip, op, ltab + +begin + op = 1 + ip = 1 + + repeat { + ltab = ip + while (line[ltab] == ' ' && op <= maxch) { + ltab = ltab + 1 + if (mod(ltab, tabsize) == 1) { + outline[op] = '\t' + ip = ltab + op = op + 1 + } + } + for (; ip < ltab && op <= maxch; ip = ip + 1) { + outline[op] = ' ' + op = op + 1 + } + if (line[ip] == EOS || op >= maxch+1) + break + outline[op] = line[ip] + op = op + 1 + ip = ip + 1 + } until (line[ip] == EOS || op >= maxch+1) + + outline[op] = EOS +end diff --git a/pkg/dataio/cardimage/wcardimage.com b/pkg/dataio/cardimage/wcardimage.com new file mode 100644 index 00000000..4d80adb1 --- /dev/null +++ b/pkg/dataio/cardimage/wcardimage.com @@ -0,0 +1,8 @@ +int card_length +int cards_per_blk +int detab +int ebcdic +int ibm +char contn_string[SZ_LINE] + +common /wcardcom/ card_length, cards_per_blk, detab, ebcdic, ibm, contn_string |