Viewing contents of file '../idllib/iuedac/iuelib/pro/getiue.pro'
;******************************************************************************
;+
;*NAME:
;
; GETIUE 9 SEPTEMBER 1981
;
;*CLASS:
;
;*CATEGORY:
;
; IUESIPS
;
;*PURPOSE:
;
; Extract data from IUESIPS spectrum format.
;
;*CALLING SEQUENCE:
;
; GETIUE,IMAGET,TYPE,ORDER,H,WAVE,FLUX,EPS,unit
;
;*PARAMETERS:
;
; IMAGET (REQ) (I/O) (0) (B I L F D S)
; String = file name containing the data.
; Value = record length (bytes) of open file (input).
; Record length of file in bytes (output).
;
; TYPE (REQ) (I) (0) (B I L F D)
; Type of the flux record desired. For ESLO/MELO files, valid
; values are 1 = Gross, 2 = Background, 3 = Net, 4 = Abscal.
; For high dispersion data, 4 = ripple-corrected net flux
; and, for data processed at GSFC after 8/30/90 or at VILSPA
; after 12/21/87, 5=abscal data.
;
; ORDER (REQ) (I/O) (0) (B I L F D)
; Wavelength or order number (input).
; Order number for the data (output).
;
; H (REQ) (O) (1) (I)
; IUESIPS header record (record 0 in file).
;
; WAVE (REQ) (O) (1) (F D)
; Wavelength Vector in Angstroms.
;
; FLUX (REQ) (O) (1) (F D)
; Scaled flux vector.
;
; EPS (REQ) (O) (1) (I L F D)
; Quality vector.
;
; UNIT (OPT) (I/O) (0) (BIL)
; Logical unit number assigned to input file.
; If UNIT is specified, and IMAGET is not a string parameter,
; GETIUE uses UNIT as the logical unit number and assumes
; the file is already open. This is useful for multiple reads
; of the same file.
;
;*EXAMPLES:
;
; order = 1550 & img = 's14071h' ; Get C IV Ripple Corrected 3 Orders
; getiue,img,4,order,h,w1,f1,e1,un
; getiue,img,4,order-1,h,w2,f2,e2,un
; getiue,img,4,order+1,h,w0,f0,e0,un
; free_lun,un
;
; getiue,'s14586s',1,100,h,w,f,e ; Center of Line-by-Line
; close,/all
;
; For multiple orders of high dispersion absolute fluxes:
;
; nam = 'swp39095hlg'
; getiue,nam,5,100,h,w,f,e,un ; order 100
; getiue,nam,5,99,h,w1,f1,e1,un ; order 99
; getiue,nam,5,98,h,w2,f2,e2,un ; order 98
; free_lun,un
;
;*SYSTEM VARIABLES USED:
;
; none
;
;*INTERACTIVE INPUT:
;
; none
;
;*SUBROUTINES CALLED:
;
; PARCHECK
; PCHECK
; DECOMPOSE
; CHKFITS
; TABINV
;
;*FILES USED:
;
; Data is taken from file imaget.DAT when a string is input.
;
;*SIDE EFFECTS:
;
; Does not close the file it opened - must be done in the
; calling program (or manually) using the FREE_LUN command.
;
;*RESTRICTIONS:
;
; Not for used with fits formatted files.
;
;*PROCEDURE:
;
; Imaget is used to open the file or assumes the file is open for
; a non-string input. The binary header record (record 0) is used
; to derive the record number of the desired order and type of
; data. The wavelength and epsilon records are extracted.
; The flux type is extracted and scaled according to the scaling
; factors in the binary header. All extracted vectors except the
; H vector are timmed to the valid number of data points recorded
; in the binary header. In addition to the vectors, the imaget
; is returned as the record size in bytes of the file; the order
; number as the order number; and the file is left open to
; facilitate repeated calls to the procedure without requiring
; repeated OPENs of the file.
;
;*I_HELP nn:
;
;*NOTES:
;
; - The range of valid types is derived from the header record and
; invalid values are limited to the valid range with a warning
; message. When a wavelength is requested, the record number is
; determined by looking at the zero point wavelengths stored in
; the header. The order number selected is returned. Any invalid
; order number is interperted as a wavelength. Wavelength scaling
; uses the value in the header record unless that value is zero.
; In the case of zero, the zero point wavelength is examined. If
; the zero point wavelength is zero the data is assumed to be LOW
; dispersion otherwise HIGH dispersion. Any file having the IUESIPS
; extracted spectrum format can be accessed with this procedure.
; The binary header (record 0) is assumed to be integer and have the
; format defined by IUESIPS and the RDAF documents. The other records
; may be byte, integer, or floating as determined by the number of
; bytes per record and the number of samples per record (H(1)).
;
; - For recent high dispersion data, the ABSCAL record is all 0's
; for orders outside the wavelength range of the inverse sensitivity
; function. For example, for SWP orders 125 to 112 are 0's.
;
;*MODIFICATION HISTORY:
;
; F.H.SCHIFFER 3RD VERSION 1 9 SEP 1981
; Modified GSFC RDAF 19APR85 - to be compatible with XIDL - /ERROR
; 4-24-87 RWT VAX mods: add PARCHECK, & remove INSERT and Extracts
; 1-03-89 RWT add procedure call listing
; 4-16-91 PJL removed !ERR, passes the unit number to allow the
; calling program to close the file
; 4-23-91 GRA Added parameters ext and vers to call to decompose
; 7-30-91 RWT use version number in file name and remove redundant
; close and openr commands.
; 7-19-93 RWT modify for new high dispersion absolute flux vector and
; update prolog
; 16 Nov 93 PJL added CHKFITS; correct PARCHECK call
;
;-
;******************************************************************************
pro getiue,imaget,type,order,h,wave,flux,eps,un
;
npar = n_params(0)
if (npar eq 0) then begin
print,'GETIUE,IMAGET,TYPE,ORDER,H,WAVE,FLUX,EPS,unit'
retall
endif ; npar
parcheck,npar,[7,8],'GETIUE'
pcheck,imaget,1,100,1111 ; check input
pcheck,type,2,100,0111
pcheck,order,3,100,0111
;
; get file
;
s = size(imaget)
if (s(s(0)+1) eq 7) then begin ; have file name
decompose,imaget,disk,uic,name,ext,vers
fname = disk + uic + name + '.dat' + vers
;
; make sure not a fits file
;
chkfits,fname,newsips,/silent
if (newsips) then begin
print,fname + ' is a fits formatted file.'
print,'ACTION: retall'
retall
endif ; newsips
;
openr,un,fname,/get_lun,ERROR=err
if (err ne 0) then begin ; error
print,'GETIUE returning with no data'
retall ; getiue - error
endif ; err
rec = assoc(un,intarr(20))
first = rec(0)
nbyt = first(0)
;;; endif $ ; file name
;;; else nbyt = imaget ; assume file is open
endif else begin
if (npar eq 7) then begin
print,'Logical unit number assigned to input file must be included ' + $
'in this case.'
print,'ACTION: retall'
retall
endif ; npar eq 7
nbyt = imaget ; assume file is open
endelse ; s(s(0)+1) eq 7
as = assoc(un,intarr(nbyt/2))
;
; get header information
;
h = as(0)
nsam = h(1)
nord = h(2)
ntyp = h(5)
w0 = h(100:nord+99)
iord = h(200:nord+199)
len = h(300:nord+299)
;
if ( (type le 0) or (type ge ntyp-1) ) then begin ; illegal type
print,' ILLEGAL TYPE - maximum is ',ntyp-2
type = type > 1 < (ntyp-2)
print,' type assumed to be ',type
endif ; type
;
; get data type
;
nb = fix(nbyt/nsam) ; length of sample
if (nb eq 1) then as = assoc(un,bytarr(nbyt))
if (nb eq 4) then as = assoc(un,fltarr(nbyt/4))
;
; locate correct order number
; allow user to specify wavelength
;
irec = where((iord eq order),count)
if (count le 0) then begin ; not an order number try wavelength
if (nord gt 1) then tabinv,w0,order,irec $ ;interpolate
else irec = 0 ;only have one order
irec = fix(irec)
endif else irec = irec(0)
len = len(irec)
w0 = w0(irec)
;
; get scale factors
;
if (type le 4) then begin
scj = h(type*4+16)
sck = h(type*4+17)
endif else begin ; for type = 5
scj = h(64)
sck = h(65)
endelse ; type le 4
scw = h(56)
if (scw le 0) then if (w0 le 0.) then scw = 5 else scw = 500
;
; get data we desire
;
wave = float(as(0:len-1,irec*ntyp+1))/scw + w0
eps = as(0:len-1,irec*ntyp+2)
flux = float(as(0:len-1,irec*ntyp+type+2))*scj / (2.0^sck)
;
; return values for additional calls
; leave file open for such calls
;
order = iord(irec)
imaget = nbyt
;
return
end ; getiue