aboutsummaryrefslogtreecommitdiff
path: root/pkg/dataio/bintext/t_txtbin.x
blob: 038a71ecf5e4c0873edc8cab31cf24b8580a9fa7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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