Viewing contents of file '../idllib/iuedac/iuelib/pro/getradec.pro'
;************************************************************************
;+
;*NAME:
;
;    	GETRADEC
;  
;*CLASS:
;
;	Data Manipulation
;  
;*CATEGORY:
;  
;*PURPOSE:
;
;    	To extract the RA, DEC, and observation date from IUE disk files.
;  
;*CALLING SEQUENCE:
;
;    	GETRADEC,IMAGET,RJD,RA,DEC
;  
;*PARAMETERS:
;
;    	IMAGET	(REQ) (I) (0) (S)
;		Standard file identification or file name,
;               (e.g., 'SWP12345L')
;         
;       RJD     (REQ) (O) (0) (F)
;               observation date in julian days - 240000.
;
;       RA      (REQ) (O) (0) (F)
;               target right ascension in decimal degrees
;
;       DEC     (REQ) (O) (0) (F)
;               target declination in decimal degrees
;
;  
;*EXAMPLES:
;
;*SYSTEM VARIABLES USED:
;  
;  	!noprint
;  
;*INTERACTIVE INPUT:
;
;       User is prompted for missing values of date, RA, or DEC.
;  
;*SUBROUTINES CALLED:
;
;       IUE_PARSE
;       PARCHECK
;       PCHECK
;       YESNO
;       EXPOFIN
;  	
;*FILES USED:
;
;     	IMAGET.DAT and/or IMAGET.LAB
;  
;*SIDE EFFECTS:
;  
;*RESTRICTIONS:
;  
;*NOTES:
;
;       tested with IDL Version 2.1.0 (sunos sparc)	 03 Oct 91
;       tested with IDL Version 2.1.0 (ultrix mispel)	N/A
;       tested with IDL Version 2.1.0 (vms vax)          03 Oct 91
;  
;*PROCEDURE:
;
;       The appropriate values are extracted from the scale factor record.
;       If not found, values are extracted from the label.
;	If not found, the user is prompted for values.
;  
;*I_HELP nn:
;  
;*MODIFICATION HISTORY:
;
;    VERSION 1 BY R. THOMPSON 12/28/89
;   25 Jan 1991 Add call to EXPOFIN (llt)
;   14 Mar 1991 Convert to sun (llt)
;   25 Jul 1991 LLT convert to lowercase, clean up, update prolog, tested on VAX
;   26 Jul 1991 PJL tested on SUN; updated prolog
;    7 Aug 1991 PJL added version number; tested on SUN and VAX; updated prolog
;   30 Sep 1991 RWT correct negative declination error for early IUE images
;-
;*******************************************************************
pro getradec,imaget,rjd,ra,dec
;
npar = n_params(0)
if npar eq 0 then begin
  print,' GETRADEC,IMAGET,RJD,RA,DEC'
  retall 
endif    ;npar eq 0
parcheck,npar,4,'GETRADEC'
pcheck,imaget,1,100,1000
flag = 0
imaget = strupcase(imaget)
;
; Determine input file type
;
iue_parse,imaget,disk,uic,cam,image,type,aper,ext,ver
file = disk+uic+cam+image+type+aper
dfile = file + '.dat' + ver
lfile = file + '.lab' + ver
dfile = strlowcase(dfile)   ;For UNIX
lfile = strlowcase(lfile)   ;For UNIX
rjd = 0d
ra = 0d
dec = 0d
flag = 0
ok = ''
;
; if header record is available (i.e. in .DAT file), extract available values
;
if (type eq 'r') or (type eq 'p') or (type eq 'f') then flag = 0 else flag=1
if (flag) then begin
   flag = 0                                         ; RESET FLAG
   get_lun,lund
   openr,lund,dfile
   rec = assoc(lund,intarr(600))
   h = rec(0)
   free_lun,lund
   if total(h(6:9)) ne 0 then begin
      yr  = double(h(6))
      day = double(h(7))
      hr  = double(h(8))
      mn  = double(h(9))
      if (yr gt 1900) then yr = yr - 1900.D0
      rjd = 43508.5d0+365.d0*(yr-78.d0)+1.d0*fix( (yr-77.d0)/4.d0 + 1.0d-04) $
            + day + (hr + mn/60.d0)/24.d0
      flag = flag + 1    & print,'Obs. date found in scale factor record.'
   endif    ;total(h(6:9)) ne 0
   if total(h(42:44)) ne 0 then begin
      rahr=double(h(42))
      ramin=double(h(43))
      rasec=double(h(44))/10.
      ra = (rahr+ramin/60.d0+rasec/3600.d0)
      flag = flag + 1   & print,'R.A. found in scale factor record.'
   endif    ;total(h(42:44)) ne 0
   if total(h(45:47)) ne 0 then begin
      dsign = 1
      if ( (h(45) lt 0) or (h(46) lt 0) or (h(47) lt 0) ) then dsign = -1
      decdeg=double(abs(h(45)))
      arcmin=double(abs(h(46)))
      arcsec=double(abs(h(47)))
      dec = (decdeg+arcmin/60.d0+arcsec/3600.d) * dsign
      flag = flag + 1  & print,'Dec. found in scale factor record.'
   endif   ;total(h(45:47)) ne 0
endif     ; INPUT FROM HEADER
;
; OPEN LABEL FILE ASSOCIATED WITH IMAGET TO FIND MISSING INFO
;
if (flag ne 3) then begin
   get_lun,lun
   openr,lun,lfile 
   rec = assoc(lun,bytarr(74)) 
   hrec=assoc(lun,intarr(37))
   h = hrec(0)    
   nl = h(2)
;
; Find observation date
;
   if (rjd eq 0.d) then begin
      expofin,lun,midt,expt       ;Extract Obs. date and exp. time from label
      yr=midt(0)                         ;Year of obs.date
      day=midt(1)                        ;Day number of obs.date
      hr=midt(2)                         ;Hour of obs. date
      mn=midt(3)                         ;Decimal minute of obs. date
      rjd = 43508.5d0+365.d0*(yr-78.d0)+1.d0*fix( (yr-77.d0)/4.d0 + 1.0d-04) $
             + day + (hr + mn/60.0)/24.d0
      if (expt ne 0.0) then begin        ;If exp. time and mid-time of obs.
        flag = flag + 1                  ;found in label ...
        print,'Obs. date found in label.'
      endif     ;non-zero exp time
   endif    ;rjd eq 0
;
; Find RA and DEC
;
   if (nl gt 37) and (ra eq 0) then begin 
      line = rec(37)
      ebcdic,line            ;Convert from EBCDIC to ASCII byte array
      line=string(line)      ;Convert to string
      bl   = byte(line)
      ble  = bl(0:6)                    ;Right ascension
      ble  = ble(where(ble ne 42))      ;Get rid of asterisks
      sl   = string(ble)                  
      rahr = fix(strmid(sl,1,2))
      ramin= fix(strmid(sl,3,2))
      rasec= double(strmid(sl,5,n_elements(ble)-4))/10.d0
      ra   = (rahr+ramin/60.d0+rasec/3600.d0)
      sl   = string(bl)
      dsign = strmid(sl,8,1)
      decdeg= fix(strmid(sl,9,2))
      arcmin= fix(strmid(sl,11,2))
      arcsec= fix(strmid(sl,13,2))
      dec = (decdeg+arcmin/60.d0+arcsec/3600.d)
      if (dsign eq '-') then dec = -dec
      if (ra ne 0.d) and (dec ne 0.d) then begin
          flag = flag + 2          
          print,'R.A. and dec. found in label.'
      endif   ;ra and dec non-zero
   endif   ;nl gt 37, ra eq 0
   free_lun,lun 
endif            ; INPUT FROM LABEL
;
; Prompt user if values still missing
;
if (flag ne 3) then begin
   if (rjd eq 0.d) then repeat begin
        print,' '
        print,'Observation date in Year, Day, Hour, Minute'
        read,' ',yr,day,hr,mn
        print,"$(1x,4(a,i4))",'   Yr:',fix(yr), $
          '     Day:',fix(day),'     Hr:',fix(hr),'     Min:',fix(mn)
        ok=''
        read,'Are these values correct ? (Y/N)',ok
        yesno,ok
        rjd = 43508.5d0+365.d0*(yr-78.d0)+1.d0*fix( (yr-77.d0/4.d) + 1.0d-04) $
            + day + (hr + mn/60.d0)/24.d0
   endrep until ok  ;if rjd eq 0
   if (ra eq 0.d) then repeat begin
        print,' '
        print,'Right Ascension in Hours, Minutes, Seconds '
        read,' ',rahr,ramin,rasec
        print,"$(1x,3(a,i4))", $
          '   Hrs:',fix(rahr),'     Min:',fix(ramin),'     Sec:',fix(rasec)
        ok=''
        read,'Are these values correct ? (Y/N)',ok
        yesno,ok
        ra   = (rahr+ramin/60.d0+rasec/3600.d0)
   endrep until ok   ;ra eq 0
   if (dec eq 0) then repeat begin
        print,' '
        print,'Declination in Degrees, Arc minutes, Arc seconds '
        read,' ',decdeg,arcmin,arcsec
        print,"$(1x,3(a,i4))",'   Degrees:',fix(decdeg),'     Arc min:', $
          fix(arcmin),'     Arc sec:',fix(arcsec)
        ok=''
        read,'Are these values correct ? (Y/N)',OK
        yesno,ok
        dec = (decdeg+arcmin/60.d0+arcsec/3600.d)
        print,' '
   endrep until ok      ;dec eq 0
endif                          ; input from user
;
; print results if !NOPRINT = 0
;
if !noprint eq 0 then begin
   print,"$(1x,'  Julian Date =',F12.3)",rjd
   print,"$(1x,'  Right Ascension (hr) =',F9.3)",ra
   print,"$(1x,'  Declination (deg) =',F9.3)",dec
endif                          ; print final values
;
return
end  ;  GETRADEC