aboutsummaryrefslogtreecommitdiff
path: root/noao/imred/vtel/readss4.x
blob: 2ab3199da8f3bfea91ba76c5d6053836e8d21b47 (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
include <mach.h>
include	<imhdr.h>
include <fset.h>
include	"vt.h"

define	WDSBRSTR	50

# READSS4 -- Read data file from tape or disk and format the data into
# an IRAF image.  This is for type 4 sector scans.

procedure readss4 (inputfd, filenumber, brief, select, bright, velocity, hs)

int	inputfd			# file descriptor for input (usually tape)
int	filenumber		# file number on tape
bool	brief			# short output file names
bool	select			# flag to make select image
bool	bright			# flag to make bright image
bool	velocity		# flag to make velocity image
int	hs			# header data structure pointer

pointer	im, srp
char	imagefile[SZ_FNAME]
int	date, hour, minute, seconds, i, j, num, lrs
short	u[SWTH_HIGH]

int	read()
pointer	immap(), impl2s()
errchk	immap, impl2s

begin
	# Calculate the time.  Assemble the output image name.
	hour = int(VT_HTIME(hs)/3600)
	minute = int((VT_HTIME(hs) - hour * 3600)/60)
	seconds = int(VT_HTIME(hs) - hour * 3600 - minute * 60)
	if (brief) {
	    call sprintf (imagefile[1], SZ_FNAME, "s%03d")
	        call pargi (filenumber)
	} else {
	    call sprintf (imagefile[1], SZ_FNAME, "s%02d_%02d%02d_%03d")
	        call pargi (VT_HDAY(hs)) # day of month
	        call pargi (hour)
	        call pargi (minute)
	        call pargi (filenumber)
	}

	if (select) {
	    im = immap (imagefile, NEW_IMAGE, 0)
	    IM_NDIM(im) = 2
	    IM_LEN(im,1) = SWTH_HIGH
	    IM_LEN(im,2) = VT_HNUMCOLS(hs)
	    IM_PIXTYPE(im) = TY_SHORT
	    call imaddi (im, "obs_time", VT_HTIME(hs))
	    date = VT_HMONTH(hs) * 10000 + VT_HDAY(hs) * 100 + VT_HYEAR(hs)
	    call imaddi (im, "obs_date", date )
	    call imaddi (im, "wv_lngth", VT_HWVLNGTH(hs))
	    call imaddi (im, "obs_type", VT_HOBSTYPE(hs))
	    call imaddi (im, "av_intns", VT_HAVINTENS(hs))
	    call imaddi (im, "num_cols", VT_HNUMCOLS(hs))
	    call imaddi (im, "intg/pix", VT_HINTGPIX(hs))
	    call imaddi (im, "rep_time", VT_HREPTIME(hs))
	}

	do j = 1, VT_HNUMCOLS(hs) {
	    if (select)
	        srp = impl2s (im, j)

	    iferr (num = read (inputfd, u, SWTH_HIGH*SZB_SHORT/SZB_CHAR)) {
		call fseti (inputfd, F_VALIDATE, lrs*SZB_SHORT/SZB_CHAR)
		call eprintf ("Error on tape read.\n")
		num = read (inputfd, u, SWTH_HIGH*SZB_SHORT/SZB_CHAR)
	    }
	    lrs = num
	    if (num < SWTH_HIGH*SZB_SHORT/SZB_CHAR)
	        call error (0, "eof encountered when reading file")
	    if (BYTE_SWAP2 == YES)
	        call bswap2 (u, 1, u, 1, SWTH_HIGH * SZB_SHORT)

	    if (select)
	        do i = 1, 512
		    Mems[srp+i-1] = u[i]
	}

	if (select)
	    call imunmap (im)
end