aboutsummaryrefslogtreecommitdiff
path: root/pkg/tbtables/tbtnam.x
blob: 2cf68e050814de5589cc7af9e8a21ab827069514 (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
include <tbset.h>
include "tbtables.h"
define	SZ_SCRATCH	11

# tbtnam -- get table name
# Get the name of a table which has been opened or at least initialized.
#
# Phil Hodge, 16-Jun-1995  Modify for FITS tables.
# Phil Hodge,  2-Feb-1996  Option to include TB_HDU or TB_EXTVER.
# Phil Hodge,  7-Jun-1999  Replace TB_F_TYPE by TB_TYPE.

procedure tbtnam (tp, tblname, maxch)

pointer tp			# i: pointer to table descriptor
char	tblname[ARB]		# o: the name of the table
int	maxch			# i: maximum number of characters in name
#--
char    scratch[SZ_SCRATCH]     # scratch for appending EXTVER
 
begin
	# Use the source name/url if it is present.
	if (TB_SRC_PTR(tp) != NULL) {
	    call strcpy (TB_SRC(tp), tblname, maxch)
	    return
	}

	call strcpy (TB_NAME(tp), tblname, maxch)
 
	if (TB_TYPE(tp) == TBL_TYPE_FITS || TB_TYPE(tp) == TBL_TYPE_CDF) {
 
	    # This will be non-null only if the user specified a name.
	    if (TB_EXTNAME(tp) != EOS) {

		call strcat ("[", tblname, maxch)
		call strcat (TB_EXTNAME(tp), tblname, maxch)

		if (TB_EXTVER(tp) > 0) {
		    call sprintf (scratch, SZ_SCRATCH, ",%d")
			call pargi (TB_EXTVER(tp))
		    call strcat (scratch, tblname, maxch)
		}
		call strcat ("]", tblname, maxch)

	    } else if (TB_HDU(tp) >= 0) {

		call sprintf (scratch, SZ_SCRATCH, "[%d]")
		    call pargi (TB_HDU(tp))
		call strcat (scratch, tblname, maxch)
	    }
	}
end