; Make information data of FOV, QS_BP locations 
; IDL> .r gtinfo_qsbp_xrt_20230219
;goto, PNG 
;------------------
yyyymmdd='20230219'
;------------------
yyyy=strmid(yyyymmdd,0,4)
mm=strmid(yyyymmdd,4,2)
dd=strmid(yyyymmdd,6,2)
;
dir='/www/HINODE/XRT/SCIA/synop_images/syncmp_FITS/'
files0=file_search(dir+yyyy+'/'+mm+'/comp_XRT'+yyyymmdd+'_*.fits')
mreadfits,files0,index0,data0
;--------------------------------------------
ss=[3,4]  ; Al_mesh, Al_poly image selection
;--------------------------------------------
files=files0(ss)
index=index0(ss)
data=data0(*,*,ss)
help,index,data
;
;stop
wdef,0,1024,1024
stepper,index,safe_log10(data)
ndata=n_elements(index)
info_am=get_info(index(0),/nonint)
info_ap=get_info(index(1),/nonint)
;---------------------------------------
r_val=0.3   ; within 0.3Rs
;---------------------------------------
;
ii_am=index(0) & dd_am=data(*,*,0)
ii_ap=index(1) & dd_ap=data(*,*,1)
rad=get_rb0p(ii_ap,/rad,/quiet)  ; solar radius Rs
rad_pix=rad/ii_ap.xscale         ;
rad2_pix=rad*r_val/ii_ap.xscale
;
;*** shift Al_poly image: Sun-center to image center ***
sftx=round(ii_ap.xcen/ii_ap.xscale)
sfty=round(ii_ap.ycen/ii_ap.yscale)
dd2_ap=shift(dd_ap,sftx,sfty)
;
;*** rotate Al_poly images: Sun's North is up ***
ang=ii_ap.crota2*(-1)
magfact=1.0 & cx=512 & cy=512
dd3_ap=rot(dd2_ap,ang,magfact,cx,cy,/pivot,/interp)
;
tvscl,safe_log10(dd3_ap)
;
;--- draw FOV circle ---
draw_circle,cx,cy,rad2_pix,/dev
fov_xyr=[cx,cy,rad2_pix]*1.0
;
;------------------------------------------------------
;--- work area to determine BP location and radius ---
;cursor,xx,yy,/dev,/down & print,xx,yy
;rad=10 & draw_circle,xx,yy,rad,/dev
;------------------------------------------------------
;--- make bp info array ---
bp_rad=fltarr(10)
bp_xy=fltarr(2,10)
ndata=n_elements(bp_rad)
;------------------------------------------
bp_rad(0)=12 & bp_xy(*,0)=[495,429] 
bp_rad(1)=12 & bp_xy(*,1)=[589,498] 
bp_rad(2)=15 & bp_xy(*,2)=[598,442] 
bp_rad(3)=15 & bp_xy(*,3)=[446,509] 
bp_rad(4)=13 & bp_xy(*,4)=[559,398] 
;------------------------------------------
for i=0,ndata-1 do draw_circle,bp_xy(0,i),bp_xy(1,i),bp_rad(i),/dev
;
;--- make final info structure ---
ss=where(bp_rad ne 0,nn_bp)
bp_xyr=fltarr(3,nn_bp)
bp_xyr(0,*)=bp_xy(0,0:nn_bp-1)
bp_xyr(1,*)=bp_xy(1,0:nn_bp-1)
bp_xyr(2,*)=bp_rad(0:nn_bp-1)
;
info_str=create_struct('file_am',files(0),'file_ap',files(1), $
                        'fov_xyr',fov_xyr, $
                        'bp_xyr',bp_xyr)
help,info_str,/str
yn='n'
read,prompt='*** save info_structure? [y/n] ',yn
if yn eq 'y' then begin $
  outdir='/disk/yla/takeda/REU_2026/qsbp_info/'
  fname='qsbp_info_'+yyyymmdd
  text='Created by GTINFO_QSBP_XRT_'+yyyymmdd+'.PRO. '+ $
       'A structure contains info of '+ $
       'file_am(Al_mesh filename), file_ap(Al_poly filename), '+ $
       'fov_xyr(FOV center and radius in pix), '+ $
       'bp_xyr (Bright Point center and radius in pix).'
  name=['qsbp_info']
  savegen,info_str,file=outdir+fname,text=text,name=name
endif
;
FIN:
end
