
; reading
restore,'lso_comp-s_lev4.0_20221102_090718_wave0656_pa023_obse_maparr.xdr',/ver
maparr_h=maparr
nw_h=n_elements(maparr_h.wavelength)
nx=n_elements(maparr(0).data(*,0)) & ny=n_elements(maparr(0).data(0,*))
;maparr_h=maparr_h(1:nw_h-1-1)
maparr_h(0).data=replicate(0.0,nx,ny) & maparr_h(nw_h-1).data=replicate(0.0,nx,ny)
restore,'lso_comp-s_lev4.0_20221102_090932_wave0587_pa023_obse_maparr.xdr',/ver
maparr_he=maparr
nw_he=n_elements(maparr_he.wavelength)
;maparr_he=maparr_he(1:nw_he-1-1)
maparr_he(0).data=replicate(0.0,nx,ny) & maparr_he(nw_he-1).data=replicate(0.0,nx,ny)

xpos_example=700 & ypos_example=310

goto,stat_tmp1

; plot_map
loadct,3
window,2,xs=900,ys=800
plot_map,maparr_h(5),window=2,title=' H I 656.28 nm - at about line center'
loadct,8
window,0,xs=900,ys=800
plot_map,maparr_he(6),window=0,title=' He I 587.67 nm - at about line center'

stop

; plot_comps_map
loadct,3
window,2,xs=900,ys=800
plot_comps_map,maparr_h(5),window=2,title=' H I 656.28 nm - at about line center'
loadct,8
window,0,xs=900,ys=800
plot_comps_map,maparr_he(6),window=0,title=' He I 587.67 nm - at about line center'

stop

; plot_map video in a common scale
nw_h=n_elements(maparr_h.wavelength)
w_h_str=strtrim(maparr_h.wavelength,2)
i_min_h=min(maparr_h.data) & i_max_h=max(maparr_h.data)
wset,2
loadct,3
for w=0,nw_h-1 do begin
   plot_map, maparr_h(w),title=' H I '+w_h_str(w)+' nm',drange=[i_min_h,i_max_h]
   print,' H I '+w_h_str(w)+' nm'
   wait,1
end

nw_he=n_elements(maparr_he.wavelength)
w_he_str=strtrim(maparr_he.wavelength,2)
i_min_he=min(maparr_he.data) & i_max_he=max(maparr_he.data)
wset,0
loadct,8
for w=0,nw_h-1 do begin
   plot_map, maparr_he(w),title=' He D3 I '+w_he_str(w)+' nm',drange=[i_min_he,i_max_he]
   print,' He D3 I '+w_he_str(w)+' nm'
   wait,1
end

stop
stat_tmp1:

; line_profiles
window,1,xs=1000,ys=600
!p.multi=[0,1,2]
plot,maparr_h.wavelength,maparr_h.data(xpos_example,ypos_example), $
     tit=' H I profile, xpos='+strtrim(string(xpos_example),2)+' '+ $
                      ' ypos='+strtrim(string(ypos_example),2)
measured_errors_h=replicate(0.0005,nw_h)
errplot,maparr_h.wavelength,maparr_h.data(xpos_example,ypos_example)-measured_errors_h,$
                            maparr_h.data(xpos_example,ypos_example)+measured_errors_h
plot,maparr_he.wavelength,maparr_he.data(xpos_example,ypos_example), $
     tit=' He I D3 profile, xpos='+strtrim(string(xpos_example),2)+' '+ $
     ' ypos='+strtrim(string(ypos_example),2)
measured_errors_he=replicate(0.00002,nw_he)
errplot,maparr_he.wavelength,maparr_he.data(xpos_example,ypos_example)-measured_errors_he,$
                             maparr_he.data(xpos_example,ypos_example)+measured_errors_he
!p.multi=0

stop
;Result = GAUSSFIT( X, Y [, A] [, CHISQ=variable] [, ESTIMATES=array] [, MEASURE_ERRORS=vector] [, NTERMS=integer{3 to 6}] [, SIGMA=variable] [, YERROR=variable])

maparr_h.data(xpos_example,ypos_example)=maparr_h.data(xpos_example,ypos_example)*100000.
measured_errors_h=measured_errors_h*100000.
fit_h = GAUSSFIT(maparr_h.wavelength,$;-maparr_h(0).wavelength,$
        maparr_h.data(xpos_example,ypos_example),coeff_h,$
        measure_errors=measured_errors_h, nterms=4,sigma=sigma_h, yerror=yerror_h)
maparr_he.data(xpos_example,ypos_example)=maparr_he.data(xpos_example,ypos_example)*100000.
measured_errors_he=measured_errors_he*100000.
fit_he = GAUSSFIT(maparr_he.wavelength, maparr_he.data(xpos_example,ypos_example),coeff_he,measure_errors=measured_errors_he,  nterms=4, sigma=sigma_he,yerror=yerror_he)

maparr_h.data(xpos_example,ypos_example)=maparr_h.data(xpos_example,ypos_example)/100000.
measured_errors_h=measured_errors_h/100000.
maparr_he.data(xpos_example,ypos_example)=maparr_he.data(xpos_example,ypos_example)/100000.
measured_errors_he=measured_errors_he/100000.
fit_h=fit_h/100000.
fit_he=fit_he/100000.
yerror_h=yerror_h/100000.
yerror_he=yerror_he/100000.
coeff_h(0)=coeff_h(0)/100000. & coeff_h(3)=coeff_h(3)/100000.
coeff_he(0)=coeff_he(0)/100000. & coeff_he(3)=coeff_he(3)/100000.

window,3
!p.multi=[0,1,2]
plot,maparr_h.wavelength,maparr_h.data(xpos_example,ypos_example), $
     tit=' H I profile, xpos='+strtrim(string(xpos_example),2)+' '+ $
     ' ypos='+strtrim(string(ypos_example),2),$
     yrange=[0,max(maparr_h.data(xpos_example,ypos_example))*1.2]
errplot,maparr_h.wavelength,maparr_h.data(xpos_example,ypos_example)-measured_errors_h,$
                            maparr_h.data(xpos_example,ypos_example)+measured_errors_h
oplot,maparr_h.wavelength,fit_h,psym=-4,symsize=2,thick=3
errplot, maparr_h.wavelength,fit_h-yerror_h, $
                             fit_h+yerror_h,thick=3
w_int=findgen(100)*(max(maparr_h.wavelength)-min(maparr_h.wavelength))/100.+$
      maparr_h(0).wavelength(0)
oplot,w_int,gaussian(w_int,coeff_h)

plot,maparr_he.wavelength,maparr_he.data(xpos_example,ypos_example), $
     tit=' He I D3 profile, xpos='+strtrim(string(xpos_example),2)+' '+ $
     ' ypos='+strtrim(string(ypos_example),2),$
     yrange=[0,max(maparr_he.data(xpos_example,ypos_example))*1.2]
errplot,maparr_he.wavelength,maparr_he.data(xpos_example,ypos_example)-measured_errors_he,$
        maparr_he.data(xpos_example,ypos_example)+measured_errors_he
oplot,maparr_he.wavelength,fit_he,psym=-4,symsize=2,thick=3
errplot, maparr_he.wavelength,fit_he-yerror_he, $
         fit_he+yerror_he,thick=3
w_int=findgen(100)*(max(maparr_he.wavelength)-min(maparr_he.wavelength))/100.+$
      maparr_he(0).wavelength(0)
oplot,w_int,gaussian(w_int,coeff_he)
!p.multi=0

stop

end


