pro synscan,filename 
;+ 
; NAME: 
;             SYNSCAN 
; 
; PURPOSE: 
;             This routine scans an image file and creates a  
;             constant radius scan for synoptic maps. 
; 
; CATEGORY: 
;             REDUCTION 
; 
; CALLING SEQUENCE: 
;             SYNSCAN,Filename 
; 
; INPUTS: 
;             Filename:   Ascii string of the name of the  
;                         FITS file 
; 
; OPTIONAL INPUTS: 
;             None 
;        
; KEYWORD PARAMETERS: 
;             None 
; 
; OUTPUTS: 
;             None 
; 
; OPTIONAL OUTPUTS: 
;             None 
; 
; COMMON BLOCKS: 
;             None 
; 
; SIDE EFFECTS: 
;             Creates a FITS file of the constant radius  
;             scans in the current directory
; 
; RESTRICTIONS: 
;             The directory containing the FITS file should 
;             be the local directory or !imgdir should be set
;             to point to the directory
; 
; PROCEDURE: 
; 
; EXAMPLE: 
; 
; MODIFICATION HISTORY: 
;       Written by:     RA Howard, NRL, 26 Nov 1995. 
;    Version 1     26 Nov 95 Initial Release 
;    Version 2     13 Apr 96 Modified for keywords
; 
;	@(#)synscan.pro	1.2 01/19/00 LASCO IDL LIBRARY
;- 
ver='2' 
; 
;  Read in FITS image, and pick up various parameters 
; 
check_imgdir
readfits,!imgdir+filename,image,hdr 
detector = fxpar (hdr,'DETECTOR') 
s = size(image) 
ncol = s(1) 
nrow = s(2) 
suncol = fxpar(hdr,'CENTER_X') 		; center of sun
sunrow = fxpar(hdr,'CENTER_Y') 		; center of sun
IF (suncol eq 0) THEN BEGIN
   suncol = FXPAR (hdr,'OCCULT_X')
   sunrow = FXPAR (hdr,'OCCULT_Y')
   IF (suncol EQ 0)  THEN BEGIN
      cntr = OCCLTR_CNTR(hdr)
      suncol = cntr(0)
      sunrow = cntr(1)
   ENDIF
ENDIF
solrol = fxpar(hdr,'ANGLE') 		; solar roll angle
sunsize = fxpar(hdr,'SOLAR_R') 		; solar radius in arc seconds
IF (sunsize EQ 0)   THEN sunsize=60*16
; 
;   Set parameters of scans based on detector number 
; 
case detector of 
'C1':  begin 
          minrad = 1.1 
          delrad = 0.05 
          nrad   = fix((3-minrad)/delrad +1.1) 
          subt   = subtense('C1') 	; arc sec per pixel
       end 
'C2':  begin 
          minrad = 1.7 
          delrad = 0.1 
          nrad   = fix((6-minrad)/delrad +1.1) 
          subt   = subtense('C2') 
       end 
'C3':  begin 
          minrad = 3.5 
          delrad = 0.5 
          nrad   = fix((30-minrad)/delrad +1.1) 
          subt   = subtense('C3') 
       end 
else:  begin 
          print,'Error in SYNRADSCAN: Camera unknown',$ 
                 detector 
          return 
       end 
endcase 
; 
;   Set up for scans 
; 
;   SOLROL is the angle from the top of the image clockwise to 
;   the solar north point. 
; 
;    
theta = findgen(360)/!radeg+solrol 
cs    = cos(theta) 
sn    = sin(theta) 
fac   = sunsize/subt       ; conversion from radii to pixels 
scan  = fltarr(360,nrad) 
; 
;  for each radius compute the scan 
; 
for i=0,nrad-1 do begin 
   r = (i*delrad+minrad)*fac 
   col = suncol - r*sn 
   row = sunrow - r*cs 
   icol = fix(col) 
   irow = fix(row) 
   k = irow*ncol+icol 
   b1 = image(k) 
   b2 = image(k+1) 
   b3 = image(k+ncol) 
   b4 = image(k+(ncol+1)) 
   del = col-icol 
   b12 = b1+(b2-b1)*del 
   b34 = b3+(b4-b3)*del 
   scan(0,i) = b12+(b34-b12)*(row-irow) 
endfor 
; 
;   Make file name for output FITS file 
; 
len = strlen(filename) 
outname = strmid(filename,len-12,9)+'cr' 
b=byte(strmid(outname,1,1))-byte('0') 
if (b lt 5) then b='u' else b='c' 
outname = outname+b 
; 
;   Create directory for scan 
; 
;newdir = getenv_slash('IMAGES')+'synoptic/' 
;date_obs = fxpar(hdr,'DATE-OBS') 
;time_obs = fxpar(hdr,'TIME-OBS') 
;date = date_obs+' '+time_obs 
; use CDS time routines to create YYYYMMDD 
;newdir = newdir+yyddmm 
;cd,newdir,current=olddir 
; 
;  Add/Correct FITS header parameters 
; 
get_utc,dte,/ecs 
fxaddpar,hdr,'DATE',dte 
fxaddpar,hdr,'NAXIS1',360 
fxaddpar,hdr,'NAXIS2',nrad 
fxaddpar,hdr,'CTYPE1','POSANG' 
fxaddpar,hdr,'CTYPE2','RADIUS' 
fxaddpar,hdr,'CRPIX1',1 
fxaddpar,hdr,'CRPIX2',1 
fxaddpar,hdr,'CRVAL1',0. 
fxaddpar,hdr,'CRVAL2',minrad 
fxaddpar,hdr,'CDELT1',1. 
fxaddpar,hdr,'CDELT2',delrad 
fxaddpar,hdr,'HISTORY',ver+' synscan,"'+filename+'"' 
writefits,outname,scan,hdr 
return 
end 

