aboutsummaryrefslogtreecommitdiff
path: root/noao/imred/vtel/readss2.x
blob: 71ae8758843f18e40f61f808999459f6a790d715 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
include <mach.h>
include	<imhdr.h>
include <fset.h>
include	"vt.h"

define	WDSBRSTR	50

# READSS2 -- Read a type 2 sector scan from tape and format into 3 iraf images.
# Type two sector scans consist of three images with 16 bits per
# pixel.  The three images are 1. velocity (16 bits) 2. select (16 bits) and
# 3.  brightness (16 bits).  The images are 512 pixels high.

procedure readss2 (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

char	velimage[SZ_FNAME]	# velocity image
char	selimage[SZ_FNAME]	# select image
char	britimage[SZ_FNAME]	# brightness image
short	u[SWTH_HIGH]
int	date, hour, minute, seconds, i, j, num, lrs
pointer	velim, selim, britim, velsrp, selsrp, britsrp

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

begin
	# Calculate the time.  Assemble the output image names.
	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 (velimage[1], SZ_FNAME, "v%03d")
	        call pargi (filenumber)
	    call sprintf (selimage[1], SZ_FNAME, "s%03d")
	        call pargi (filenumber)
	    call sprintf (britimage[1], SZ_FNAME, "b%03d")
	        call pargi (filenumber)
	} else {
	    call sprintf (velimage[1], SZ_FNAME, "v%02d_%02d%02d_%03d")
	        call pargi (VT_HDAY(hs)) # day of month
	        call pargi (hour)
	        call pargi (minute)
	        call pargi (filenumber)
	    call sprintf (selimage[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)
	    call sprintf (britimage[1], SZ_FNAME, "b%02d_%02d%02d_%03d")
	        call pargi (VT_HDAY(hs)) # day of month
	        call pargi (hour)
	        call pargi (minute)
	        call pargi (filenumber)
	}

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

	do j = 1, VT_HNUMCOLS(hs) {
	    if (select)
	        selsrp = impl2s (selim, j)
	    if (bright)
	        britsrp = impl2s (britim, j)
	    if (velocity)
	        velsrp = impl2s (velim, 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 (velocity)
		do i = 1, 512
		    Mems[velsrp+i-1] = u[i]

	    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[selsrp+i-1] = u[i]

	    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 (bright)
		do i = 1, 512
		    Mems[britsrp+i-1] = u[i]
	}

	# Unmap images.
	if (select)
	    call imunmap (selim)
	if (velocity)
	    call imunmap (velim)
	if (bright)
	    call imunmap (britim)
end