Viewing contents of file '../idllib/ghrs/pro/adstring.pro'
Function adstring,ra_dec,dec,precision
;+
; NAME:
; ADSTRING
; PURPOSE:
; Return RA and Dec as character string in sexigesimal format.
; RA and Dec may be entered as either a 2 element vector or as
; 2 scalars. You may also specify the precision of the declination
; in digits after the decimal point.
; CALLING SEQUENCE
; RESULT = ADSTRING(DEC) ;Convert scalar to sexigesimal string
; RESULT = ADSTRING(RA_DEC,[PRECESION])
; RESULT = ADSTRING(RA,DEC,[PRECISION])
; INPUTS:
; RA_DEC - 2 element vector giving the right ascension and declination
; in decimal degrees.
; RA - Right ascension in decimal degrees
; DEC - Declination in decimal degrees
; PRECISION - The number of digits after the decimal of DEClination.
; The RA is automatically 1 digit more. This parameter may
; either be the third parameter after RA,DEC or the second
; parameter after [RA,DEC]. It is not available for just
; DEC. If no PRECISION parameter is passed, a precision
; of 1 for both RA and DEC is returned to maintain
; compatibility with past ADSTRING functions. A precision
; of 0 will result in the below format, always claimed, but
; but never delivered by ADSTRING.
; OUTPUT:
; RESULT - Character string containing HR,MIN,SEC,DEC,MIN,SEC formatted
; as (2I3,F5.1,2I3,I4). If only a single scalar is supplied
; it is converted to a sexigesimal string (2I3,F5.1).
; PROCEDURES CALLED:
; RADEC,ZPARCHECK,SIXTY
; EXAMPLE:
; Display CRVAL coordinates in a FITS header, H
; EXTAST,H,CD,CRPIX,CRVAL ;Extract 2 element CRVAL vector (degrees)
; PRINT,ADSTRING(CRVAL) ;Print CRVAL vector in sexigesimal format
; REVISION HISTORY:
; Written W. Landsman June 1988
; Addition of variable precision and DEC
; seconds precision fix. Only operates
; if third parameter is present to
; preserve compatibility w/ previous ver. Aug. 1990 [E. Deutsch]
; Improved round-off procedure Aug. 1990 [W. Landsman]
;-
err = 'ADSTRING: ERROR - '
arg=n_params(0)
case n_elements(ra_dec) of
1: if n_params(0) eq 1 then dec = ra_dec else ra = ra_dec
2: begin
ra = ra_dec(0) mod 360.
if (arg gt 1) then begin precision=dec & arg=3 & endif
dec = ra_dec(1)
end
else: message, $
'First parameter must be a scalar or 2 element ([RA,DEC]) vector'
endcase
if n_params(0) ge 2 then $
zparcheck,'ADSTRING',dec,2,[1,2,3,4,5],0,'Declination (degrees)'
if n_elements(ra) eq 1 then begin
if (dec lt -90.) or (dec gt 90.) then $
message,'Illegal declination value of'+strtrim(dec,2)+' degrees'
radec,ra,dec,ihr,imin,xsec,ideg,imn,xsc
if (arg lt 3) then precision=0
precision = precision>0<4 ;No more than 4 decimal places
secfmt='(F'+string(4+precision+1,'(I1)')+'.'+string(precision+1,'(I1)')+')'
if (arg lt 3) then precision=1
result = string([ihr,imin],'(2I3.2)') + string(xsec,secfmt) + ' '
endif else begin
x = sixty(dec)
precision=1
ideg = fix(x(0)) & imn = fix(x(1)) & xsc = x(2)
result = ''
endelse
if (ideg eq 0) and (min([imn,xsc]) lt 0.) then begin
deg = '-00'
imn = abs(imn) & xsc = abs(xsc)
endif else deg = string(ideg,'(I3.2)')
if (precision eq 0) then begin
secfmt='(I4.2)'
xsc = nint(xsc)
endif else $
secfmt='(F'+string(4+precision,'(I1)')+'.'+string(precision,'(I1)')+')'
if nint(xsc+0.5/10^precision) ge 60 then begin ;Appropiate roundoff
xsc = 0.
imn = imn + 1
endif
return,result + deg + string(imn,'(I3.2)') + string(xsc,secfmt)
end