aboutsummaryrefslogtreecommitdiff
path: root/noao/twodspec/apextract/apio.x
blob: bfd2c6e638af6686768024f390a7ba274e69b500 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
include	<time.h>

# AP_LOG -- Verbose, log, and error output.

procedure ap_log (str, log, verbose, err)

char	str[ARB]	# String
int	log		# Write to log if logfile defined?
int	verbose		# Write to stdout if verbose?
int	err		# Write to stdout?

int	fd, open()
long	clktime()
bool	clgetb()
pointer	sp, logfile, date
errchk	open

begin
	call smark (sp)
	call salloc (logfile, SZ_LINE, TY_CHAR)
	call salloc (date, SZ_DATE, TY_CHAR)
	call cnvdate (clktime(0), Memc[date], SZ_DATE)

	if (err == YES || (verbose == YES && clgetb ("verbose"))) {
	    call printf ("%s: %s\n")
	        call pargstr (Memc[date])
	        call pargstr (str)
	    call flush (STDOUT)
	}

	if (log == YES) {
	    call clgstr ("logfile", Memc[logfile], SZ_FNAME)
	    if (Memc[logfile] != EOS) {
	        fd = open (Memc[logfile], APPEND, TEXT_FILE)
	        call fprintf (fd, "%s: %s\n")
	            call pargstr (Memc[date])
	            call pargstr (str)
	        call flush (fd)
	        call close (fd)
	    }
	}

	call sfree (sp)
end


# AP_GOPEN/AP_GCLOSE -- Open and close the graphics device.
# The device "stdgraph" is used.

procedure ap_gopen (gp)

pointer	gp		# GIO pointer
pointer	gplast		# Last GIO pointer

int	flag
pointer	gopen()
errchk	gopen

data	flag/NO/
common	/apgio/ gplast

begin
	if (flag == NO) {
	    flag = YES
	    call ap_gclose ()
	}

	if (gplast == NULL)
	    gplast = gopen ("stdgraph", NEW_FILE, STDGRAPH)

	gp = gplast
end

procedure ap_gclose ()

int	flag
pointer	gplast

data	flag/NO/
common	/apgio/ gplast

begin
	if (flag == NO) {
	    flag = YES
	    gplast = NULL
	}

	if (gplast != NULL) {
	    call gclose (gplast)
	    gplast = NULL
	}
end


# AP_POPEN -- Open the plot device or metacode file.  This includes CLIO
# to get the plot device.

procedure ap_popen (gp, fd, type)

pointer	gp		# GIO pointer
int	fd		# FIO channel for metacode file
char	type[ARB]	# Plot type

bool	streq(), strne()
int	open(), nowhite(), strncmp()
pointer	sp, str, gopen()
errchk	gopen, open

begin
	call smark (sp)
	call salloc (str, SZ_FNAME, TY_CHAR)
	call clgstr ("plotfile", Memc[str], SZ_LINE)

	gp = NULL
	fd = NULL
	if (nowhite (Memc[str], Memc[str], SZ_FNAME) > 0) {
	    if (strncmp ("debug", Memc[str], 5) == 0) {
		if (streq (type, Memc[str+5]) || streq ("all", Memc[str+5])) {
		    fd = open (Memc[str], APPEND, BINARY_FILE)
		    gp = gopen ("stdvdm", APPEND, fd)
		}
	    } else if (strne ("fits", type)) {
		fd = open (Memc[str], APPEND, BINARY_FILE)
		gp = gopen ("stdvdm", APPEND, fd)
	    }
	}

	call sfree (sp)
end


# AP_PCLOSE -- Close plot file.

procedure ap_pclose (gp, fd)

pointer	gp		# GIO pointer
int	fd		# FIO channel for metacode file

begin
	if (gp != NULL)
	    call gclose (gp)
	if (fd != NULL)
	    call close (fd)
end