aboutsummaryrefslogtreecommitdiff
path: root/pkg/dataio/bintext
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 /pkg/dataio/bintext
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'pkg/dataio/bintext')
-rw-r--r--pkg/dataio/bintext/mkpkg11
-rw-r--r--pkg/dataio/bintext/t_bintxt.x65
-rw-r--r--pkg/dataio/bintext/t_txtbin.x65
3 files changed, 141 insertions, 0 deletions
diff --git a/pkg/dataio/bintext/mkpkg b/pkg/dataio/bintext/mkpkg
new file mode 100644
index 00000000..ff3db34f
--- /dev/null
+++ b/pkg/dataio/bintext/mkpkg
@@ -0,0 +1,11 @@
+# Bintext library
+
+$checkout libpkg.a ../
+$update libpkg.a
+$checkin libpkg.a ../
+$exit
+
+libpkg.a:
+ t_bintxt.x
+ t_txtbin.x
+ ;
diff --git a/pkg/dataio/bintext/t_bintxt.x b/pkg/dataio/bintext/t_bintxt.x
new file mode 100644
index 00000000..13b1e328
--- /dev/null
+++ b/pkg/dataio/bintext/t_bintxt.x
@@ -0,0 +1,65 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+define MAX_RANGES 100
+
+# T_BINTXT -- Procedure to convert binary files containing only text to text
+# files.
+
+procedure t_bintxt()
+
+bool verbose
+char outfile[SZ_FNAME]
+
+char infile[SZ_FNAME], out_fname[SZ_FNAME]
+int list, len_list, in, out, file_number
+
+bool clgetb()
+int strlen(), open(), clpopni(), clplen(), clgfil()
+
+begin
+ # Get input files
+ list = clpopni ("binary_file")
+ len_list = clplen (list)
+
+ # Get output files
+ call clgstr ("text_file", outfile, SZ_FNAME)
+
+ verbose = clgetb ("verbose")
+
+ file_number = 1
+ while (clgfil (list, infile, SZ_FNAME) != EOF) {
+
+ if (len_list > 1) {
+ call strcpy (outfile, out_fname, SZ_FNAME)
+ call sprintf (out_fname[strlen(out_fname) + 1], SZ_FNAME,
+ "%03d")
+ call pargi (file_number)
+ } else
+ call strcpy (outfile, out_fname, SZ_FNAME)
+
+ iferr {
+
+ if (verbose) {
+ call printf ("File: %s -> %s\n")
+ call pargstr (infile)
+ call pargstr (out_fname)
+ }
+
+ # Open input and output files, copy and close files
+ in = open (infile, READ_ONLY, BINARY_FILE)
+ out = open (out_fname, NEW_FILE, TEXT_FILE)
+ call fcopyo (in, out)
+ call close (in)
+ call close (out)
+
+ } then {
+ if (verbose) {
+ call eprintf ("Cannot read file %s\n")
+ call pargstr (infile)
+ }
+ } else
+ file_number = file_number + 1
+ }
+
+ call clpcls (list)
+end
diff --git a/pkg/dataio/bintext/t_txtbin.x b/pkg/dataio/bintext/t_txtbin.x
new file mode 100644
index 00000000..038a71ec
--- /dev/null
+++ b/pkg/dataio/bintext/t_txtbin.x
@@ -0,0 +1,65 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+# T_TXTBIN -- Procedure to convert text files to binary files.
+
+procedure t_txtbin ()
+
+bool verbose
+char outfile[SZ_FNAME]
+
+char infile[SZ_FNAME], out_fname[SZ_FNAME]
+int list, len_list, in, out, file_number
+
+bool clgetb()
+int clpopni(), clplen(), clgfil(), strlen(), open()
+
+begin
+ # Get list of input files
+ list = clpopni ("text_file")
+ len_list = clplen (list)
+
+ # Get output file name
+ call clgstr ("binary_file", outfile, SZ_FNAME)
+
+ verbose = clgetb ("verbose")
+
+ # Loop over the files
+ file_number = 1
+ while (clgfil (list, infile, SZ_FNAME) != EOF) {
+
+ if (len_list > 1 ) {
+ call strcpy (outfile, out_fname, SZ_FNAME)
+ call sprintf (out_fname[strlen(out_fname) + 1], SZ_FNAME,
+ "%03d")
+ call pargi (file_number)
+ } else
+ call strcpy (outfile, out_fname, SZ_FNAME)
+
+ iferr {
+
+ if (verbose) {
+ call printf ("File: %s -> %s\n")
+ call pargstr (infile)
+ call pargstr (out_fname)
+ call flush (STDERR)
+ }
+
+ # Open input and output files, copy and close input and
+ # output files.
+ in = open (infile, READ_ONLY, TEXT_FILE)
+ out = open (out_fname, NEW_FILE, BINARY_FILE)
+ call fcopyo (in, out)
+ call close (in)
+ call close (out)
+
+ } then {
+ call eprintf ("Cannot read file: %s\n")
+ call pargstr (infile)
+ } else
+ file_number = file_number + 1
+ }
+ call clpcls (list)
+end
+
+
+