;+ ; Project : ASOS - FMG ; ; Name : READ_FMG.PRO ; ; Purpose : Read a FMG FITS file to obtain polarization images/vector fields and header arrays. ; ; Explanation : This routine calls the IDL Astronomy Library routine READFITS ; to read the FMG FITS file. It then fills in a FMG header ; structure with the header information. ; ; Use : IDL> read_fmg, filename, index, data, [/strength] ; ; Inputs : filename Name of the FMG FITS file. ; ; Outputs : index The index of FMG fits file; ; : data The polarized image arrays ; ; Opt. Outputs: strength Used only for Level2 data. With it, the vector fields are returned as ; three components of BL, Btx and Bty, otherwise, retured as ; total field strength, inclination and azimuth. ; ; Prev. Hist. : None. ; ; Written : Su””Jiangtao ; Preliminary””version, 2022-09-01 ; read auxiliary data, 2022-10-21 ; read tentatively realesed data, 2023-02-15 ; pro read_fmg, files, index, data, strength=strength level=strmid(file_basename(files),4,5) mode=strmid(file_basename(files),30,5) noaa_num=strmid(file_basename(files),10,2) id_cutout=strmid(file_basename(files),10,9) id_ardata=strmid(file_basename(files),49,2) case level of 'lev0C' : begin if mode eq 'scien' then begin print, 'Data of Level 0.0 include two polarized components of Stokes Q/U/V and their respective header files.' data=fltarr(4096,4096,6) data(*,*,0:1)=readfits(files,ext=1,hdrq) data(*,*,2:3)=readfits(files,ext=2,hdru) data(*,*,4:5)=readfits(files,ext=3,hdrv) index={hdrq:fitshead2struct(hdrq),hdru:fitshead2struct(hdru),hdrv:fitshead2struct(hdrv)} endif else begin data=readfits(files, hdr) index=fitshead2struct(hdr) endelse end 'lev00': begin if mode eq 'scien' then begin print, 'Data of Level 0.0 include two polarized components of Stokes Q/U/V and their respective header files.' data=fltarr(4096,4096,6) data(*,*,0:1)=readfits(files,ext=1,hdrq) data(*,*,2:3)=readfits(files,ext=2,hdru) data(*,*,4:5)=readfits(files,ext=3,hdrv) index={hdrq:fitshead2struct(hdrq),hdru:fitshead2struct(hdru),hdrv:fitshead2struct(hdrv)} endif else begin data=readfits(files, hdr) index=fitshead2struct(hdr) endelse end 'lev15': begin if id_cutout eq 'roicutout' then begin data=readfits(files, hdr) index=fitshead2struct(hdr) endif else begin print, 'Data of Level 1.5 include Stokes I, Q, U and V images and their respective header files.' data=fltarr(4096,4096,4) data(*,*,0)=readfits(files,ext=1,hdri) data(*,*,1)=readfits(files,ext=2,hdrq) data(*,*,2)=readfits(files,ext=3,hdru) data(*,*,3)=readfits(files,ext=4,hdrv) index={hdri:fitshead2struct(hdri),hdrq:fitshead2struct(hdrq),hdru:fitshead2struct(hdru),hdrv:fitshead2struct(hdrv)} endelse end 'lev20': begin if noaa_num ne 'AR' then begin data=fltarr(4096,4096,3) tmp0=readfits(files,ext=1,hdrb) tmp1=readfits(files,ext=2,hdrinc) tmp2=readfits(files,ext=3,hdrazi) index1=fitshead2struct(hdrb) index2=fitshead2struct(hdrinc) index3=fitshead2struct(hdrazi) if ~keyword_set(strength) then begin print, 'Three components of vector fields, Bl, Btx, Bty, and their respective header files' data(*,*,0)=tmp0 data(*,*,1)=tmp1 data(*,*,2)=tmp2 index={hdrb:index1,hdrinc:index2, hdrazi:index3} endif else begin print, 'Total field strength, inclination and azimuth and their respective header files' data(*,*,0)=tmp0*cos(tmp1) data(*,*,1)=tmp0*sin(tmp1)*cos(tmp2) data(*,*,2)=tmp0*sin(tmp1)*sin(tmp2) change_headerfits_full,reform(data(*,*,0)),reform(data(*,*,1)),reform(data(*,*,2)),index1,index2,index3 index={hdrbl:index1, hdrbtx:index2, hdrbty:index3} endelse endif else begin if id_ardata eq 'vb' then begin hdr=headfits(files,ext=1) nx=sxpar(hdr,'NAXIS1') ny=sxpar(hdr,'NAXIS2') data=fltarr(nx,ny,3) tmp0=readfits(files,ext=1,hdrbl) tmp1=readfits(files,ext=2,hdrbx) tmp2=readfits(files,ext=3,hdrby) index1=fitshead2struct(hdrbl) index2=fitshead2struct(hdrbx) index3=fitshead2struct(hdrby) if keyword_set(strength) then begin print, 'Three components of vector fields, Bl, Btx, Bty, and their respective header files' data(*,*,0)=tmp0 data(*,*,1)=tmp1 data(*,*,2)=tmp2 index={hdrbl:index1, hdrbtx:index2, hdrbty:index3} endif else begin print, 'Total field strength, inclination and azimuth and their respective header files' data(*,*,0)=(tmp0^2+tmp1^2+tmp2^2)^0.5 data(*,*,1)=acos(tmp0/(tmp0^2+tmp1^2+tmp2^2)^0.5) data(*,*,2)=atan(tmp2/tmp1) change_headerfits_ar,reform(data(*,*,0)),reform(data(*,*,1)),reform(data(*,*,2)),index1,index2,index3 index={hdrb:index1, hdrbinc:index2, hdrazi:index3} endelse endif if id_ardata eq 'bl' then begin print, 'Filtergram and longitudinal magnetic field' hdr=headfits(files,ext=1) nx=sxpar(hdr,'NAXIS1') ny=sxpar(hdr,'NAXIS2') data=fltarr(nx,ny,2) tmp0=readfits(files,ext=1,hdrwl) tmp1=readfits(files,ext=2,hdrbl) index1=fitshead2struct(hdrwl) index2=fitshead2struct(hdrbl) data(*,*,0)=tmp0 data(*,*,1)=tmp1 index={hdrwl:index1, hdrbl:index2} endif endelse end else: begin data=readfits(files, hdr) index=fitshead2struct(hdr) end endcase return end