aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/ptools/ptutils/t_istable.x
blob: b8cbf5db49a7a99abe36ac3932760cb219202007 (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
66
67
68
69
70
71
include "../../lib/ptkeysdef.h"

# T_ISTABLE -- Decide whether an input file is an ST Table, an APPHOT style
# text file or neither.

procedure t_istable ()

pointer	infile			# name of the input file

bool	table, text, other
int	fd, type
pointer	sp, line
int	access(), tbtopn(), open(), getline(), strmatch()
errchk	tbtopn(), open()

begin
	# Get some working space.
	call smark (sp)
	call salloc (infile, SZ_FNAME, TY_CHAR)
	call salloc (line, SZ_LINE, TY_CHAR)

	# Fetch the name of the input file
	call clgstr ("infile", Memc[infile], SZ_FNAME)
	if (access (Memc[infile], READ_ONLY, TEXT_FILE) == YES)
	    type = TEXT_FILE
	else
	    type = BINARY_FILE

	if (type == BINARY_FILE) {
	    iferr {
	        fd = tbtopn (Memc[infile], READ_ONLY, 0)
	    } then {
		table = false
		text = false
		other = true
	    } else {
		table = true
		text = false
		other = false
		call tbtclo (fd)
	    }
	} else {
	    table = false
	    iferr {
	        fd = open (Memc[infile], READ_ONLY, TEXT_FILE) 
	    } then {
	        text = false
	        other = true
	    } else {
	        Memc[line] = EOS
	        if (getline (fd, Memc[line]) != EOF) {
		    if (strmatch (Memc[line], KY_CHAR_IRAF) != 0) {
		        text = true
		        other = false
		    } else {
		        text = false
		        other = true
		    }
		}
		call close (fd)
	    }
	}

	# Store the results in the istable parameter file.
	call clputb ("table", table)
	call clputb ("text", text)
	call clputb ("other", other)

	# Free memory.
	call sfree (sp)
end