aboutsummaryrefslogtreecommitdiff
path: root/pkg/tbtables/tbtcre.x
blob: 3935b9b05ff199504a332f1d9cc2cc96a5e25138 (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
include <tbset.h>
include "tbtables.h"
include "tblerr.h"

# tbtcre -- Create a new table
# This routine is called after calling tbtopn for a new table.
# For binary tables, this routine appends the default extension.
#
# Phil Hodge, 14-Aug-1987  Error if table is already open.
# Phil Hodge, 13-Jan-1992  Add option for text table type.
# Phil Hodge,  5-Mar-1993  Deallocate comment buffer if not a text table.
# Phil Hodge, 15-Dec-1994  Table name is now SZ_LINE instead of SZ_FNAME.
# Phil Hodge, 23-Dec-1994  Add option for CDF or FITS file.
# Phil Hodge,  3-Apr-1995  Set TB_MODIFIED to true.
# Phil Hodge,  7-Jun-1999  Replace TB_F_TYPE by TB_TYPE.
# Phil Hodge, 15-Jun-1999  Reset subtype for stsdas format tables.

procedure tbtcre (tp)

pointer tp			# Pointer to table descriptor
#--
errchk	tbtext, tbvnew, tbwnew, tbfnew, tbxnew, tbynew, tbznew

begin
	if (TB_IS_OPEN(tp))
	    call error (1, "tbtcre:  table is already open")

	if (TB_TYPE(tp) == TBL_TYPE_TEXT) {		# text file
	    call tbznew (tp)

	} else if (TB_TYPE(tp) == TBL_TYPE_FITS) {	# FITS table
	    call tbfnew (tp)

	} else {

	    # For a binary table we need to check that there's an
	    # extension, and if not, append the default extension.
	    call tbtext (TB_NAME(tp), TB_NAME(tp), SZ_LINE)

	    # Will the table be stored in a CDF file?  If it's a CDF file,
	    # we'll also do the initialization for a row-ordered table.
	    if (TB_TYPE(tp) == TBL_TYPE_CDF)		# common data format
		;  # call tbvnew (tp)

	    else if (TB_TYPE(tp) == TBL_TYPE_MI)	# machine independent
		;  # call tbwnew (tp)
	    else if (TB_TYPE(tp) == TBL_TYPE_S_ROW)	# SDAS row-ordered
		call tbxnew (tp)
	    else if (TB_TYPE(tp) == TBL_TYPE_S_COL)	# SDAS column-ordered
		call tbynew (tp)
	    else
		call error (ER_TBCORRUPTED, "tbtcre:  table type is messed up")

	    # We don't need this if it's not a text table.
	    if (TB_COMMENT(tp) != NULL) {
		call mfree (TB_COMMENT(tp), TY_CHAR)
		TB_SZ_COMMENT(tp) = 0
	    }

	    # Subtype is not relevant.
	    TB_SUBTYPE(tp) = TBL_SUBTYPE_UNKNOWN
	}

	TB_IS_OPEN(tp) = true
	TB_MODIFIED(tp) = true
end