aboutsummaryrefslogtreecommitdiff
path: root/noao/mtlocal/pds/pds_read.x
blob: 0cba96d73eaadfe01993d26058f2377a29f4b9b9 (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 <error.h>
include <imhdr.h>
include	"rpds.h"

# PDS_READ -- Convert a PDS file
# An EOT is signalled by returning EOF.

int procedure pds_read (pdsfile, iraffile)

char	pdsfile[ARB], iraffile[ARB]
int	pds_fd
int	stat
long	parameters[LEN_PAR_ARRAY]
pointer	im

int	pds_read_header(), mtopen()
pointer	immap()

errchk	salloc, pds_read_header, pds_read_image, mtopen, immap, imdelete

include	"rpds.com"

begin
	# Open input PDS data
	pds_fd = mtopen (pdsfile, READ_ONLY, 0)

	if (long_header == YES || short_header == YES) {
	    if (make_image == YES) {
	        call printf ("File: %s  ")
		    call pargstr (iraffile)
	    } else {
		call printf ("File: %s  ")
		    call pargstr (pdsfile)
	    }
	    if (long_header == YES)
		call printf ("\n")
	}

	# Create IRAF image header.  If only a header listing is desired
	# then a temporary image header is created and later deleted.

	if (make_image == NO)
	    call strcpy ("dev$null", iraffile, SZ_FNAME)

	im = immap (iraffile, NEW_IMAGE, 0)

	# Read header.  EOT is signalled by an EOF status from pds_read_header.
	iferr {
	    stat = pds_read_header (pds_fd, im, parameters)
	    if (stat == EOF)
	        call printf ("End of data\n")
	    else {
	        # Create an IRAF image if desired
	        if (make_image == YES)
	            call pds_read_image (pds_fd, im, parameters)
	    }
	} then
	    call erract (EA_WARN)

	if (long_header == YES)
	    call printf ("\n")

	# Close files and clean up
	call imunmap (im)
	if (stat == EOF || make_image == NO)
	    call imdelete (iraffile)
	call close (pds_fd)

	return (stat)
end