pro click,ev COMMON shared,smspec widget_control,ev.id,get_uvalue=uval widget_control,ev.top,get_uvalue=t widget_control,t[0],get_value=files widget_control,t[2],get_value=tt widget_control,t[3],get_value=st widget_control,t[4],get_value=xt widget_control,t[5],get_value=yt widget_control,t[6],get_value=xrmin widget_control,t[7],get_value=xrmax widget_control,t[8],get_value=yrmin widget_control,t[9],get_value=yrmax widget_control,t[10],get_value=ytick widget_control,t[11],get_value=off widget_control,t[12],get_value=lab widget_control,t[13],get_value=chsz widget_control,t[14],get_value=dl widget_control,t[15],get_value=cut widget_control,t[16],get_value=soro widget_control,t[17],get_value=usep widget_control,t[18],get_value=xll widget_control,t[19],get_value=yll widget_control,t[20],get_value=axcol widget_control,t[21],get_value=aycol widget_control,t[22],get_value=usecolor widget_control,t[23],get_value=lstyle set_plot,'x' if n_elements(files) gt 1 then begin while files[n_elements(files)-1] eq '' do begin if n_elements(files) gt 1 then files=files[0:n_elements(files)-2] endwhile endif if uval eq 'quit' then begin widget_control,ev.top,/DESTROY getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif file_delete,varsdir+'/gatorplotvars.dat',/quiet endif if uval eq 'smth' then begin smthw=widget_base(xsize=140,ysize=140,title='Smooth') smthtype=widget_droplist(smthw,value=['Boxcar','Binomial'],title='Type:',ysize=2,uvalue='smthtype') labelnp=widget_label(smthw,value='# of points:',yoffset=48) numpts=widget_text(smthw,xsize=2,/editable,/all_events,yoffset=38,xoffset=80,uvalue='numpts') labelni=widget_label(smthw,value='# of iterations:',yoffset=80) numiter=widget_text(smthw,xsize=2,/editable,/all_events,yoffset=70,xoffset=98,uvalue='numiter') smthpl=widget_button(smthw,value='Plot',yoffset=110,uvalue='smthpl') smthex=widget_button(smthw,value='Export',yoffset=110,xoffset=37,uvalue='smthex') smthcan=widget_button(smthw,value='Cancel',yoffset=110,xoffset=86,uvalue='smthcan') widget_control,smthw,set_uvalue=[numpts,numiter] widget_control,smthw,/realize smuv='' smthtp=0 while smuv ne 'smthpl' and smuv ne 'smthcan' and smuv ne 'smthex' do begin smthev=widget_event(smthw) if smthev.id eq smthtype then smthtp=smthev.index widget_control,smthev.id,get_uvalue=smuv endwhile widget_control,smthev.top,get_uvalue=smtht widget_control,smtht[0],get_value=smthnp widget_control,smtht[1],get_value=smthni widget_control,smthev.top,/DESTROY if smuv eq 'smthpl' then uval='plot' if smuv eq 'smthex' then uval='export' smthar=[1,smthtp,smthnp,smthni] endif if uval eq 'plot' OR uval eq 'export' then begin k=1 mpex=-1 auto=-1 listcheck,files if !p.multi[0] eq 100 then begin !p.multi[0]=0 auto=0 autofiles=files k=n_elements(files) endif for r=1,k do begin if auto eq 0 then files=[autofiles[r-1]] mp=!p.multi[1]*!p.multi[2] savefits='' doplot=0 if n_elements(smthar) eq 0 then smthar=[0] if uval eq 'export' then begin exportw=widget_base(xsize=150,ysize=405,title='Export') labelf=widget_label(exportw,value='Filename:') exportf=widget_text(exportw,xsize=18,/editable,/all_events,yoffset=18,uvalue='exportf') exporttp=cw_bgroup(exportw,['Postscript','JPEG','FITS','Printer','PDF','Screenshot .PS','Print Screenshot','Screenshot PDF','ASCII'],label_top='Save as:',yoffset=50,/column,/frame,/exclusive,uvalue='exporttp',set_value=0) exportclr=cw_bgroup(exportw,['Color','Greyscale'],yoffset=335,/row,/frame,/exclusive,uvalue='exportclr',set_value=0) exportb=widget_button(exportw,value='Export',yoffset=375,uvalue='exportb') exportcancel=widget_button(exportw,value='Cancel',yoffset=375,xoffset=60,uvalue='exportcancel') widget_control,exportw,set_uvalue=[exportf,exporttp,exportclr] widget_control,exportw,/realize exuval='' while exuval ne 'exportb' and exuval ne 'exportcancel' do begin exportev=widget_event(exportw) widget_control,exportev.id,get_uvalue=exuval endwhile widget_control,exportev.top,get_uvalue=exportt widget_control,exportt[0],get_value=exportfile widget_control,exportt[1],get_value=exporttype widget_control,exportt[2],get_value=expclr if exuval eq 'exportcancel' then begin exporttype=-1 doplot=-1 endif exportfile=exportfile[0] widget_control,exportev.top,/DESTROY if exporttype eq 0 OR exporttype eq 3 OR exporttype eq 4 then begin psoptions=widget_base(xsize=165,ysize=125,title='PS Options') labelpsx=widget_label(psoptions,value='Xsize (in):') psx=widget_text(psoptions,xsize=6,/editable,/all_events,yoffset=18,uvalue='psx') labelpsy=widget_label(psoptions,value='Ysize (in):',xoffset=80) psy=widget_text(psoptions,xsize=6,/editable,/all_events,yoffset=18,xoffset=80,uvalue='psy') if exporttype eq 0 then begin labelpsenc=widget_label(psoptions,value='Type:',yoffset=62) psenc=cw_bgroup(psoptions,['.ps','.eps'],yoffset=52,xoffset=50,/row,/frame,/exclusive,uvalue='psenc',set_value=0) endif else begin psenc=0 psencap=0 endelse psfinalize=widget_button(psoptions,value='Finalize',yoffset=95,uvalue='psfinalize') psnofinal=widget_button(psoptions,value="Don't Finalize",yoffset=95,xoffset=65,uvalue='psnofinal') widget_control,psoptions,set_uvalue=[psx,psy,psenc] widget_control,psoptions,/realize psouval='' while psouval ne 'psfinalize' and psouval ne 'psnofinal' do begin psoev=widget_event(psoptions) widget_control,psoev.id,get_uvalue=psouval endwhile widget_control,psoev.top,get_uvalue=psot widget_control,psot[0],get_value=psoxs widget_control,psot[1],get_value=psoys if exporttype eq 0 then widget_control,psot[2],get_value=psencap widget_control,psoev.top,/DESTROY if psouval eq 'psfinalize' then psfn=0 else psfn=-1 set_plot,'ps' if strcompress(psoxs[0]) eq '' then psoxs=7 else psoxs=psoxs[0] if strcompress(psoys[0]) eq '' then psoys=5 else psoys=psoys[0] if psencap eq 0 then begin if exporttype eq 3 then exportfile='idl.ps' if exporttype eq 4 AND strpos(exportfile,'.pdf') ne -1 then exportfile=strmid(exportfile,0,strpos(exportfile,'.pdf')) if expclr eq 0 then device,filename=exportfile,xs=psoxs,ys=psoys,/inches,/color if expclr eq 1 then device,filename=exportfile,xs=psoxs,ys=psoys,/inches endif else begin if expclr eq 0 then device,filename=exportfile,xs=psoxs,ys=psoys,/inches,/color,/encapsulated if expclr eq 1 then device,filename=exportfile,xs=psoxs,ys=psoys,/inches,/encapsulated endelse endif if exporttype eq 1 OR (exporttype gt 4 AND exporttype lt 8) then doplot=-1 if exporttype eq 2 then savefits=exportfile if mp gt 1 then begin if auto eq 0 then mpex=0 if exporttype ne 1 AND exporttype lt 5 then uval='plot' endif endif else begin if mp eq 1 then set_plot,'x' endelse if doplot ne -1 then begin readdata,files,tt[0],st[0],xt[0],yt[0],xrmin[0],xrmax[0],yrmin[0],yrmax[0],ytick,off,lab,chsz[0],dl[0],cut[0],soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys if smthar[0] eq 1 then smoothplot,smthar,xs,ys makeplot,files,tt[0],st[0],xt[0],yt[0],xrmin[0],xrmax[0],yrmin[0],yrmax[0],ytick,off,lab,chsz[0],dl[0],cut[0],soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys endif if uval eq 'export' then if exporttype eq 8 then begin savexy=fltarr(2,n_elements(xs[0,*])) savexy[0,*]=xs[0,*] savexy[1,*]=ys[0,*] openw,1,exportfile printf,1,savexy close,1 return endif if mpex eq 0 AND r eq k then uval='export' if uval eq 'export' then begin if exporttype eq 0 then begin print,psfn if psfn eq 0 then begin device,/close endif else begin getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif openw,2,varsdir+'/temp.gp' printf,2,0 close,2 endelse endif if exporttype eq 1 then begin if expclr eq 0 then write_jpeg,exportfile,tvrd(true=1),true=1 if expclr eq 1 then write_jpeg,exportfile,tvrd() endif if exporttype eq 3 then begin if psfn eq 0 then begin device,/close spawn,'lpr idl.ps' spawn,'rm idl.ps' endif else begin getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif openw,2,varsdir+'/temp.gp' printf,2,3 close,2 endelse endif if exporttype eq 4 then begin if psfn eq 0 then begin device,/close p2pcom='ps2pdf '+exportfile+' '+exportfile+'.pdf' spawn,p2pcom spawn,'rm '+exportfile endif else begin getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif openw,2,varsdir+'/temp.gp' printf,2,4 printf,2,exportfile close,2 endelse endif if exporttype gt 4 then begin if exporttype eq 6 then exportfile='idl.ps' if exporttype eq 7 AND strpos(exportfile,'.pdf') ne -1 then exportfile=strmid(exportfile,0,strpos(exportfile,'.pdf')) psencap=0 if exporttype eq 5 AND strpos(exportfile,'.eps') ne -1 then psencap=1 set_plot,'x' if expclr eq 0 then begin jp=tvrd(true=1) jpblk=where(jp[0,*,*] eq 0 and jp[1,*,*] eq 0 and jp[2,*,*] eq 0) jpwht=where(jp[0,*,*] eq 255 and jp[1,*,*] eq 255 and jp[2,*,*] eq 255) if jpwht[0] eq -1 then jpwht=where(jp[0,*,*] ge 248 and jp[1,*,*] ge 248 and jp[2,*,*] ge 248) jp[jpblk*3]=255 jp[jpblk*3+1]=255 jp[jpblk*3+2]=255 if jpwht[0] ne -1 then jp[jpwht*3]=0 if jpwht[0] ne -1 then jp[jpwht*3+1]=0 if jpwht[0] ne -1 then jp[jpwht*3+2]=0 endif else begin jp=tvrd() jpblk=where(jp eq 0) jpwht=where(jp eq 255) if jpwht[0] eq -1 then jpwht=where(jp ge 248) jp[jpblk]=255 if jpwht[0] ne -1 then jp[jpwht]=0 endelse set_plot,'ps' if expclr eq 0 then begin if psencap eq 0 then device,filename=exportfile,/color if psencap eq 1 then device,filename=exportfile,/color,/encapsulated tv,jp,true=1 endif else begin if psencap eq 0 then device,filename=exportfile if psencap eq 1 then device,filename=exportfile,/encapsulated tv,jp endelse device,/close if exporttype eq 6 then begin spawn,'lpr idl.ps' spawn,'rm idl.ps' endif if exporttype eq 7 then begin p2pcom='ps2pdf '+exportfile+' '+exportfile+'.pdf' spawn,p2pcom spawn,'rm '+exportfile endif set_plot,'x' endif endif if mpex eq 0 AND r eq k then begin if psfn eq 0 then set_plot,'x' endif endfor endif if uval eq 'draw' then begin cursor,cx,cy,/nowait,/data if ev.press eq 1 then print,'X: '+strcompress(string(cx))+' Y: '+strcompress(string(cy)) endif if uval eq 'addtext' then begin widget_control,ev.top,get_uvalue=t addtextxy,t[1] endif if uval eq 'psfin' then begin device,/close getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif close,2 openr,2,varsdir+'/temp.gp' readf,2,exporttype if exporttype eq 3 then begin spawn,'lpr idl.ps' spawn,'rm idl.ps' endif if exporttype eq 4 then begin exportfile='' readf,2,exportfile p2pcom='ps2pdf '+exportfile+' '+exportfile+'.pdf' spawn,p2pcom spawn,'rm '+exportfile endif close,2 spawn,'rm '+varsdir+'/temp.gp' set_plot,'x' endif if uval eq 'browse' then begin defdir='' if file_test('$HOME/.gatorplot') eq 1 then begin openr,1,'$HOME/.gatorplot' gpcfg=strarr(3) readf,1,gpcfg close,1 defdir=strmid(gpcfg[where(strmid(gpcfg,0,6) eq 'BROWSE')],10,150) defdir=strcompress(defdir[0],/remove_all) endif else begin if file_test('$GATORPLOT/.gatorplot') eq 1 then begin openr,1,'$GATORPLOT/.gatorplot' gpcfg=strarr(3) readf,1,gpcfg close,1 defdir=strmid(gpcfg[where(strmid(gpcfg,0,6 eq 'BROWSE'))],10,150) defdir=strcompress(defdir[0],/remove_all) endif endelse fl=dialog_pickfile(filter=defdir,/multiple_files) widget_control,ev.top,get_uvalue=browset widget_control,browset[0],get_value=flcurr if strcompress(flcurr[0],/remove_all) eq '' then begin widget_control,browset[0],set_value=fl endif else begin widget_control,browset[0],set_value=fl,/append endelse endif if uval eq 'maths' then begin listcheck,files savefits='' readdata,files,tt[0],st[0],xt[0],yt[0],xrmin[0],xrmax[0],yrmin[0],yrmax[0],ytick,off,lab,chsz[0],dl[0],cut[0],soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys n=n_elements(files) mathmenu=widget_base(xsize=270,ysize=440,title='Maths') labelmfmenu1=widget_label(mathmenu,value='File(s):') labelmscale1=widget_label(mathmenu,value='Scale by:',xoffset=135) labelmoffs1=widget_label(mathmenu,value='x-Offset:',xoffset=205) mfmenu1=widget_list(mathmenu,/multiple,value=files,xsize=18,ysize=5,yoffset=20,uvalue='mfmenu1') mscale1=widget_text(mathmenu,xsize=5,ysize=5,/editable,/all_events,xoffset=145,yoffset=20,uvalue='mscale1') moffs1=widget_text(mathmenu,xsize=5,ysize=5,/editable,/all_events,xoffset=205,yoffset=20,uvalue='moff1s') labelmconst1=widget_label(mathmenu,value='+Constant:',yoffset=134) mconst1=widget_text(mathmenu,xsize=4,/editable,/all_events,yoffset=128,xoffset=68,uvalue='mconst1') moper=cw_bgroup(mathmenu,['+','-','*','/'],yoffset=165,/row,/frame,/exclusive,uvalue='moper',label_top='Operation:',set_value=0) labelmfmenu2=widget_label(mathmenu,value='File(s):',yoffset=234) labelmscale2=widget_label(mathmenu,value='Scale by:',yoffset=234,xoffset=135) labelmoffs2=widget_label(mathmenu,value='x-Offset:',yoffset=234,xoffset=205) mfmenu2=widget_list(mathmenu,/multiple,value=files,xsize=18,ysize=5,yoffset=255,uvalue='mfmenu2') mscale2=widget_text(mathmenu,xsize=5,ysize=5,/editable,/all_events,xoffset=145,yoffset=255,uvalue='mscale2') moffs2=widget_text(mathmenu,xsize=5,ysize=5,/editable,/all_events,xoffset=205,yoffset=255,uvalue='moffs2') labelmconst2=widget_label(mathmenu,value='+Constant:',yoffset=368) mconst2=widget_text(mathmenu,xsize=4,/editable,/all_events,yoffset=362,xoffset=68,uvalue='mconst2') mmplot=widget_button(mathmenu,value='Plot',yoffset=405,uvalue='mmplot') mmsave=widget_button(mathmenu,value='Save',yoffset=405,xoffset=60,uvalue='mmsave') mmcancel=widget_button(mathmenu,value='Cancel',yoffset=405,xoffset=120,uvalue='mmcancel') widget_control,mathmenu,set_uvalue=[mscale1,moffs1,mconst1,moper,mscale2,moffs2,mconst2] widget_control,mathmenu,/realize mmuv='' while mmuv ne 'mmplot' and mmuv ne 'mmsave' and mmuv ne 'mmcancel' do begin mmev=widget_event(mathmenu) widget_control,mmev.id,get_uvalue=mmuv endwhile widget_control,mmev.top,get_uvalue=mmt widget_control,mmt[0],get_value=mmscale1 widget_control,mmt[1],get_value=mmoffs1 widget_control,mmt[2],get_value=mmconst1 widget_control,mmt[3],get_value=mmoper widget_control,mmt[4],get_value=mmscale2 widget_control,mmt[5],get_value=mmoffs2 widget_control,mmt[6],get_value=mmconst2 flist1=widget_info(mfmenu1,/list_select) flist2=widget_info(mfmenu2,/list_select) widget_control,mmev.top,/DESTROY mmscl1=fltarr(n_elements(flist1)) mmoff1=fltarr(n_elements(flist1)) for j=0,n_elements(flist1)-1 do begin if j lt n_elements(mmscale1) then begin if mmscale1[j] ne 0 then mmscl1[j]=mmscale1[j] else mmscl1[j]=1 endif else mmscl1[j]=1 if j lt n_elements(mmoffs1) then mmoff1[j]=mmoffs1[j] else mmoff1[j]=0 endfor mmscl2=fltarr(n_elements(flist2)) mmoff2=fltarr(n_elements(flist2)) for j=0,n_elements(flist2)-1 do begin if j lt n_elements(mmscale2) then begin if mmscale2[j] ne 0 then mmscl2[j]=mmscale2[j] else mmscl2[j]=1 endif else mmscl2[j]=1 if j lt n_elements(mmoffs2) then mmoff2[j]=mmoffs2[j] else mmoff2[j]=0 endfor getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gatorplotvars.dat' mmin=xrmin[0] mmax=xrmax[0] if mmin eq 0 then mmin=min(xs[0,*]) if mmax eq 0 then mmax=max(xs[0,*]) mmelem=where(xs[0,*] ge mmin AND xs[0,*] le mmax) mcdelt=(xs[0,mmelem[0]+1]-xs[0,mmelem[0]]) mmaxoff1=max(mmoff1)/mcdelt mmaxoff2=max(mmoff2)/mcdelt mmnpts=n_elements(mmelem) mmxs=fltarr(mmnpts+(mmaxoff1n_elements(x) endfor if nmax lt 2 then nmax=10 xs=fltarr(nrows,nmax) ys=fltarr(nrows,nmax) xs[*]=-1 usep2=intarr(nrows) lstyle2=intarr(nrows) usecolor2=fltarr(nrows) irow = 0 for j=0,n-1 do begin if strmid(files[j],0,4) eq 'f(x)' then functplot,files[j],x,y,fsame,fnpts,funxmin,funxmax,j,xs,xmin,xmax else if strpos(strlowcase(files[j]),'.fit') ne -1 then fitsplot,files[j],x,y else asciiplot,files[j],x,y,xc[j],yc[j],linskp[j],colsame,axcol,aycol szy=size(y) if szy[0] eq 1 then begin xs[irow,0:n_elements(x)-1]=x ys[irow,0:n_elements(x)-1]=y if irow lt n_elements(usep) then usep2[irow]=usep[irow] else usep2[irow]=0 if irow lt n_elements(lstyle) then lstyle2[irow]=lstyle[irow] else begin if soro eq 0 then lstyle2[irow]=0 else lstyle2[irow]=irow MOD 6 endelse if irow lt n_elements(usecolor) then begin if strpos(usecolor[irow],' ') ne -1 then begin usecolor2[irow]=get_color(strparse(usecolor[irow],1),strparse(usecolor[irow],2),strparse(usecolor[irow],3)) endif else usecolor2[irow]=usecolor[irow]+0. if usecolor[irow] eq '' then usecolor2[irow]=!p.color endif else usecolor2[irow]=!p.color irow = irow+1 endif else begin for l=0,szy[2]-1 do begin xs[irow,0:n_elements(x)-1]=x ys[irow,0:n_elements(x)-1]=y[*,l,0] if irow lt n_elements(usep) then usep2[irow]=usep[irow] else usep2[irow]=0 if irow lt n_elements(lstyle) then lstyle2[irow]=lstyle[irow] else begin if soro eq 0 then lstyle2[irow]=0 else lstyle2[irow]=irow MOD 6 endelse if irow lt n_elements(usecolor) then begin if strpos(usecolor[irow],' ') ne -1 then begin usecolor2[irow]=get_color(strparse(usecolor[irow],1),strparse(usecolor[irow],2),strparse(usecolor[irow],3)) endif else usecolor2[irow]=usecolor[irow]+0. if usecolor[irow] eq '' then usecolor2[irow]=!p.color endif else usecolor2[irow]=!p.color irow = irow+1 endfor endelse endfor if strcompress(cut,/remove_all) ne '' then begin gcut = where(ys gt cut) if gcut[0] ne -1 then ys[gcut] = cut endif n = nrows ay=fltarr(n) ay[0]=0 if ytick eq 1 then begin ytn=strarr(2*n+1) ytn[*]=' ' ytn[0]='0' if strcompress(dl,/remove_all) ne '' then ytn[1]=strcompress(dl,/remove_all) ytv=fltarr(2*n) ytv[0]=0 if strcompress(dl,/remove_all) ne '' then begin ytv[1]=dl+0.0 ytnum=2*n endif else ytnum=n endif noff=n_elements(off) for j=1,n-1 do begin ayz=max(ys[j-1,*]) if j le noff then begin if strcompress(off[j-1],/remove_all) ne '' then ay[j]=off[j-1]+0.0 else ay[j]=ay[j-1]+floor(10.^ceil(alog10(1./ayz))*ayz+.99)/10.^ceil(alog10(1./ayz)) endif else begin ay[j]=ay[j-1]+floor(10.^ceil(alog10(1./ayz))*ayz+.99)/10.^ceil(alog10(1./ayz)) endelse if ytick eq 1 then begin ytv[(ytnum/n)*j]=ay[j] ytv[(ytnum/n)*j+1]=ay[j]+dl+0.0 endif endfor if strcompress(ymin,/remove_all) eq '' then ymin=min(ys[0,*]) if strcompress(ymax,/remove_all) eq '' then begin ymax=max(ys[0,*]) for j=1,n-1 do ymax=ymax+max(ys[j,*]) if soro eq 1 then ymax=max(ys) ymax=ymax*1.1 if ymax lt ay[n-1]+max(ys[n-1,*]) then ymax=ay[n-1]+max(ys[n-1,*]) endif if strcompress(xmin,/remove_all) eq '' then xmin=min(xs) if strcompress(xmax,/remove_all) eq '' then xmax=max(xs) getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif save, /variables, filename=varsdir+'/gatorplotvars.dat' end pro smoothplot,smthar,xs,ys getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gatorplotvars.dat' npt=smthar[2] if smthar[1] eq 0 then begin for j=1,smthar[3] do begin ysmooth=fltarr(n,nmax) for l=npt/2,nmax-1-npt/2 do begin for r=0,n-1 do begin ysmooth[r,l]=avg(ys[r,l-npt/2:l+npt/2]) endfor endfor ys[*,npt/2:nmax-1-npt/2]=ysmooth[*,npt/2:nmax-1-npt/2] endfor endif else begin binsm=[1] for j=2,npt do begin binsm2=fltarr(j) binsm2[0]=1 binsm2[j-1]=1 for l=1,j-2 do begin binsm2[l]=binsm[l-1]+binsm[l] endfor binsm=binsm2 endfor binsm=binsm/total(binsm) for j=1,smthar[3] do begin ysmooth=fltarr(n,nmax) for l=npt/2,nmax-1-npt/2 do begin for r=0,n-1 do begin for i=0,npt-1 do begin ysmooth[r,l]=ysmooth[r,l]+ys[r,l-npt/2+i]*binsm[i] endfor endfor endfor ys[*,npt/2:nmax-1-npt/2]=ysmooth[*,npt/2:nmax-1-npt/2] endfor endelse getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif save, /variables, filename=varsdir+'/gatorplotvars.dat' end pro makeplot,files,tt,st,xt,yt,xmin,xmax,ymin,ymax,ytick,off,lab,chsz,dl,cut,soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gatorplotvars.dat' if ytick eq 1 then begin if xll eq 0 AND yll eq 0 then plot,[0],[0],xrange=[xmin,xmax],xstyle=1,yrange=[ymin,ymax],ystyle=1,title=tt,subtitle=st,xtitle=xt,ytitle=yt,xmargin=[5,7],charsize=chsz,yticks=ytnum,ytickname=ytn,ytickv=ytv,/nodata if xll eq 1 AND yll eq 0 then plot,[1],[0],xrange=[xmin,xmax],xstyle=1,yrange=[ymin,ymax],ystyle=1,title=tt,subtitle=st,xtitle=xt,ytitle=yt,xmargin=[5,7],charsize=chsz,yticks=ytnum,ytickname=ytn,ytickv=ytv,/nodata,/xlog if xll eq 0 AND yll eq 1 then plot,[0],[1],xrange=[xmin,xmax],xstyle=1,yrange=[ymin,ymax],ystyle=1,title=tt,subtitle=st,xtitle=xt,ytitle=yt,xmargin=[5,7],charsize=chsz,yticks=ytnum,ytickname=ytn,ytickv=ytv,/nodata,/ylog if xll eq 1 AND yll eq 1 then plot,[1],[1],xrange=[xmin,xmax],xstyle=1,yrange=[ymin,ymax],ystyle=1,title=tt,subtitle=st,xtitle=xt,ytitle=yt,xmargin=[5,7],charsize=chsz,yticks=ytnum,ytickname=ytn,ytickv=ytv,/nodata,/xlog,/ylog endif else begin if xll eq 0 AND yll eq 0 then plot,[0],[0],xrange=[xmin,xmax],xstyle=1,yrange=[ymin,ymax],ystyle=1,title=tt,subtitle=st,xtitle=xt,ytitle=yt,xmargin=[5,7],charsize=chsz,/nodata if xll eq 1 AND yll eq 0 then plot,[1],[0],xrange=[xmin,xmax],xstyle=1,yrange=[ymin,ymax],ystyle=1,title=tt,subtitle=st,xtitle=xt,ytitle=yt,xmargin=[5,7],charsize=chsz,/nodata,/xlog if xll eq 0 AND yll eq 1 then plot,[0],[1],xrange=[xmin,xmax],xstyle=1,yrange=[ymin,ymax],ystyle=1,title=tt,subtitle=st,xtitle=xt,ytitle=yt,xmargin=[5,7],charsize=chsz,/nodata,/ylog if xll eq 1 AND yll eq 1 then plot,[1],[1],xrange=[xmin,xmax],xstyle=1,yrange=[ymin,ymax],ystyle=1,title=tt,subtitle=st,xtitle=xt,ytitle=yt,xmargin=[5,7],charsize=chsz,/nodata,/xlog,/ylog endelse nlab=n_elements(lab) if soro eq 0 then begin for j=0,n-1 do begin oplot,xs[j,where(xs[j,*] ne -1)],ay[j]+ys[j,where(xs[j,*] ne -1)],psym=usep2[j],linestyle=lstyle2[j],color=usecolor2[j] if strcompress(dl,/remove_all) ne '' then begin oplot,[xmin,xmax],[ay[j]+dl,ay[j]+dl],linestyle=1 endif if j lt nlab then xyouts,xmax+((xmax+0.0)-(xmin+0.0))*.005,ay[j]+dl,lab[j],charsize=chsz,alignment=0.0,/data endfor endif else begin for j=0,n-1 do begin oplot,xs[j,where(xs[j,*] ne -1)],ys[j,where(xs[j,*] ne -1)],linestyle=lstyle2[j],psym=usep2[j],color=usecolor2[j] if strcompress(dl,/remove_all) ne '' then oplot,[xmin,xmax],[dl,dl],linestyle=1 if j lt nlab then xyouts,xmax+((xmax+0.0)-(xmin+0.0))*.005,ymax-((ymax+0.0)-(ymin+0.0))/n*j,lab[j],charsize=chsz,alignment=0.0,/data endfor endelse if savefits ne '' then begin yfits=ys[0,where(xs[0,*] ge xmin AND xs[0,*] le xmax)] yfits=fltarr(n_elements(yfits)) yfits[*]=ys[0,where(xs[0,*] ge xmin AND xs[0,*] le xmax)] fits_write,savefits,yfits fits_read,savefits,yfits,header h2=strarr(n_elements(header)+3) h2[0:n_elements(header)-2]=header[0:n_elements(header)-2] h2[n_elements(header)-1]='CRVAL1 = '+string(xmin) h2[n_elements(header)]='CDELT1 = '+string(xs[0,1]-xs[0,0]) h2[n_elements(header)+1]='CD1_1 = '+string(xs[0,1]-xs[0,0]) h2[n_elements(header)+2]=header[n_elements(header)-1] fits_write,savefits,yfits,h2 endif end pro fitsplot,f,x,y COMMON shared,smspec fits_read,f,y,header s = size (y) sz = s[1] val = sxpar (header,'CRVAL1') w=where(strmid(header,0,6) eq 'CRVAL1') ;w=where(strpos(header,'CRVAL1') ne -1) if val eq 0 and w[0] ne -1 then val=strmid(header[w[0]],9,60)+0. del = sxpar (header,'CDELT1') w=where(strmid(header,0,6) eq 'CDELT1') ;w=where(strpos(header,'CDELT1') ne -1) if del eq 0 and w[0] ne -1 then del=strmid(header[w[0]],9,60)+0. if del eq 0 then del = sxpar(header,'CD1_1') x=findgen(sz)* del + val if del eq 0 AND val eq 0 then x=findgen(sz) w = where(strmid(header,0,6) eq 'PORDER') if w[0] ne -1 then begin order = sxpar(header,'PORDER') pcoeff = fltarr(order+1) x = fltarr(sz) for j = 0, order do begin coeff = sxpar(header,'PCOEFF_'+strcompress(j,/remove_all)) x = x + coeff*findgen(sz)^j endfor endif sz = size(y) if n_elements(smspec ne 0) and sz[0] ne 1 then begin i = [strparse(smspec,1)+0] b = 2 while strparse(smspec,b) ne '' do begin temp = strparse(smspec,b)+0 if temp < sz[2] then i = [i,temp] b = b + 1 endwhile y = y[*,i] endif end pro asciiplot,f,x,y,xc,yc,linsk,colsame,axcol,aycol c=0 if aycol[0] ne '' then begin colsame=1 yc=aycol[0] xc=axcol[0] linsk=0 endif if yc eq '' then begin ascii=widget_base(xsize=150,ysize=130,title='Open '+f) labelx=widget_label(ascii,value='X-axis column:') xc=widget_text(ascii,xsize=2,/editable,/all_events,xoffset=100,uvalue='xc') labely=widget_label(ascii,value='Y-axis column:',yoffset=30) yc=widget_text(ascii,xsize=2,/editable,/all_events,yoffset=30,xoffset=100,uvalue='yc') labelsk=widget_label(ascii,value='lines to skip:',yoffset=60) lsk=widget_text(ascii,xsize=2,/editable,/all_events,yoffset=60,xoffset=100,uvalue='lsk') ok=widget_button(ascii,value='OK',yoffset=95,uvalue='ok') okall=widget_button(ascii,value='OK for all',yoffset=95,xoffset=40,uvalue='okall') widget_control,ascii,set_uvalue=[xc,yc,lsk] widget_control,ascii,/realize ev=widget_event([ok,okall]) widget_control,ev.id,get_uvalue=uval if uval eq 'okall' then colsame=1 else colsame=0 widget_control,ev.top,get_uvalue=t widget_control,t[0],get_value=xc widget_control,t[1],get_value=yc widget_control,t[2],get_value=linsk widget_control,ev.top,/DESTROY xc=xc[0] yc=yc[0] linsk=linsk[0] endif x=fltarr(100000) y=fltarr(100000) xc2=xc maxcol=0 while strpos(xc2,'+') ne -1 OR strpos(xc2,'-') ne -1 do begin pospl=strpos(xc2,'+') posmi=strpos(xc2,'-') if pospl eq -1 then pospl=10000 if posmi eq -1 then posmi=10000 maxcol=maxcol>strmid(xc2,0,posplxc2+0.0 yc2=yc while strpos(yc2,'+') ne -1 OR strpos(yc2,'-') ne -1 do begin pospl=strpos(yc2,'+') posmi=strpos(yc2,'-') if pospl eq -1 then pospl=10000 if posmi eq -1 then posmi=10000 maxcol=maxcol>strmid(yc2,0,posplyc2+0.0 a=fltarr(maxcol) close,1 openr,1,f validnum=0 skipl=-1 while validnum eq 0 do begin on_ioerror,invnum readf,1,a validnum=1 invnum: skipl=skipl+1 endwhile close,1 openr,1,f strjunk='' skipl=skipl>linsk if skipl gt 0 then for j=1,skipl do readf,1,strjunk while NOT EOF(1) do begin readf,1,a if xc ne '' then begin x[c]=0. xc2=xc curop='+' while strpos(xc2,'+') ne -1 OR strpos(xc2,'-') ne -1 do begin pospl=strpos(xc2,'+') posmi=strpos(xc2,'-') if pospl eq -1 then pospl=10000 if posmi eq -1 then posmi=10000 curcol=strmid(xc2,0,pospl 0.0 endfor gpfxs=fltarr(n_elements(xs[l,*])) gpfxs[*]=xs[l,*] gpfG=fltarr(ngauss,n_elements(gpfxs)) gpffit=fltarr(ngauss,3) for j=0,ngauss-1 do begin Z=(gpfxs-P[j*3+1,0])/P[j*3+2,0] gpfG[j,*]=P[j*3,0]*exp(-Z^2/2) gpffit[j,0]=total(gpfG[j,*])*(gpfxs[1]-gpfxs[0]) gpffit[j,1]=P[j*3+1,0] gpffit[j,2]=abs(P[j*3+2,0]*2*sqrt(2*alog(2)))*3.e+5/P[j*3+1,0] endfor print,'Multiple Gaussian fit to '+files[l] print,'X-axis ranges used in calculating the fit:' for j=0,n_elements(gpfxrng)-1 do print,gpfxrng[j] if strcompress(gpfxrng[0],/remove_all) eq '' then print,'ALL' print,'Parameters (flux, wavelength, FWHM):' for j=0,ngauss-1 do print,j+1,gpffit[j,0],gpffit[j,1],gpffit[j,2] if strcompress(gpfoutfl[0],/remove_all) eq '' then begin gpfoutfl='multgaussfit.gpfit' endif else gpfoutfl=gpfoutfl[0] if strcompress(gpfpltfl[0],/remove_all) eq '' then begin gpfpltfl='gpmultgaussfit.dat' endif else gpfpltfl=gpfpltfl[0] openw,4,gpfoutfl,/append printf,4,'Multiple Gaussian fit to '+files[l] printf,4,'X-axis ranges used in calculating the fit:' for j=0,n_elements(gpfxrng)-1 do printf,4,gpfxrng[j] if strcompress(gpfxrng[0],/remove_all) eq '' then printf,4,'ALL' printf,4,'Parameters (flux, wavelength, FWHM):' for j=0,ngauss-1 do printf,4,j+1,gpffit[j,0],gpffit[j,1],gpffit[j,2] close,4 gpfplot=fltarr(ngauss+3,n_elements(gpfxs)) gpfplot[0,*]=gpfxs gpftotfit=fltarr(n_elements(gpfxs))+gpfconst gpfplot[2,*]=gpftotfit for j=0,ngauss-1 do begin gpfplot[j+3,*]=gpfG[j,*] gpftotfit=gpftotfit+gpfG[j,*] endfor gpfplot[1,*]=gpftotfit openw,4,gpfpltfl gpfstrout='' for j=0,ngauss+2 do begin gpfstrout=gpfstrout+strcompress(gpfplot[j,*]) endfor printf,4,gpfstrout close,4 gpcolors=[get_color(255,0,0),get_color(0,255,0),get_color(0,0,255),get_color(255,160,0),get_color(255,0,255)] if soro eq 0 then begin for j=0,ngauss-1 do oplot,xs[l,*],gpfG[j,*]+gpfconst+ay[l],color=gpcolors[j MOD 5],linestyle=2 oplot,xs[l,*],gpftotfit+ay[l],color=get_color(0,255,255) endif else begin for j=0,ngauss-1 do oplot,xs[l,*],gpfG[j,*]+gpfconst,color=gpcolors[j MOD 5],linestyle=2 oplot,xs[l,*],gpftotfit,color=get_color(0,255,255) endelse endfor endif file_delete,varsdir+'/gpfitvars.dat',/quiet end pro gpfitply,files,tt,st,xt,yt,xmin,xmax,ymin,ymax,ytick,off,lab,chsz,dl,cut,soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys,draw gpfuval='' listcheck,files savefits='' readdata,files,tt,st,xt,yt,xmin,xmax,ymin,ymax,ytick,off,lab,chsz,dl,cut,soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys makeplot,files,tt,st,xt,yt,xmin,xmax,ymin,ymax,ytick,off,lab,chsz,dl,cut,soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gatorplotvars.dat' n=n_elements(files) gpfmenu=widget_base(xsize=220,ysize=240,title='Polynomial Fit') labelgpfmain=widget_label(gpfmenu,value='Fit a polynomial y=a0+a1*x+a2*x^2+...') labelgpfrange=widget_label(gpfmenu,value='Range(s):',yoffset=20) gpfrange=widget_text(gpfmenu,xsize=22,ysize=4,/editable,/all_events,yoffset=40,uvalue='gpfrange') gpfwt=cw_bgroup(gpfmenu,['None','Poisson'],yoffset=110,/column,/frame,/exclusive,label_top='Weighting:',uvalue='gpfrange',set_value=0) labelgpford=widget_label(gpfmenu,value='Order:',xoffset=85,yoffset=114) gpford=widget_text(gpfmenu,xsize=2,/editable,/all_events,xoffset=85,yoffset=135,uvalue='gpford') labelgpfinit=widget_label(gpfmenu,value='Init. Coeff:',xoffset=130,yoffset=114) gpfinit=widget_text(gpfmenu,xsize=4,ysize=4,/editable,/all_events,xoffset=135,yoffset=135,uvalue='gpfinit') gpfok=widget_button(gpfmenu,value='Fit',yoffset=210,uvalue='gpfok') gpfcancel=widget_button(gpfmenu,value='Cancel',yoffset=210,xoffset=75,uvalue='gpfcancel') widget_control,gpfmenu,set_uvalue=[gpfrange,gpfwt,gpford,gpfinit] widget_control,gpfmenu,/realize while gpfuval ne 'gpfok' and gpfuval ne 'gpfcancel' do begin gpfev=widget_event([gpfmenu,draw]) widget_control,gpfev.id,get_uvalue=gpfuval if gpfuval eq 'draw' then begin cursor,xc,yc,/nowait,/data if gpfev.press eq 1 then xran1=xc if gpfev.release eq 1 then begin widget_control,gpfrange,get_value=gpfrcurr if strcompress(gpfrcurr[0],/remove_all) eq '' then begin widget_control,gpfrange,set_value=strcompress(xran1,/remove_all)+strcompress(xc) endif else widget_control,gpfrange,set_value=strcompress(xran1,/remove_all)+strcompress(xc),/append endif endif endwhile widget_control,gpfev.top,get_uvalue=gpft widget_control,gpft[0],get_value=gpfxrng widget_control,gpft[1],get_value=gpfwght widget_control,gpft[2],get_value=gpforder widget_control,gpft[3],get_value=gpfcoeff widget_control,gpfev.top,/DESTROY if gpfuval eq 'gpfok' then begin gpforder=gpforder[0]+0 for l=0,n-1 do begin if strcompress(gpfxrng[0],/remove_all) eq '' then xfit=findgen(n_elements(xs[l,*])) else begin xrng1=strparse(gpfxrng[0],1)+0. xrng2=strparse(gpfxrng[0],2)+0. xfit=where(xs[l,*] ge xrng1 AND xs[l,*] le xrng2) if n_elements(gpfxrng) gt 1 then for j=1,n_elements(gpfxrng)-1 do begin xrng1=strparse(gpfxrng[j],1)+0. xrng2=strparse(gpfxrng[j],2)+0. xfit=[xfit,where(xs[l,*] ge xrng1 AND xs[l,*] le xrng2)] endfor endelse while n_elements(gpfcoeff) lt gpforder+1 do gpfcoeff=[gpfcoeff,''] gpfcoeff=gpfcoeff[0:gpforder]+0. gpfxs=fltarr(n_elements(xfit)) gpfys=fltarr(n_elements(xfit)) gpfxs[*]=xs[l,xfit] gpfys[*]=ys[l,xfit] if gpfwght eq 0 then weights=fltarr(n_elements(xfit))+1 if gpfwght eq 1 then weights=1./gpfys gpffit=curvefit(gpfxs,gpfys,weights,gpfcoeff,sigma,function_name='poly',itmax=100) print,strcompress(gpforder)+' Order Polynomial fit to '+files[l] print,'X-axis ranges used in calculating the fit:' for j=0,n_elements(gpfxrng)-1 do print,gpfxrng[j] if strcompress(gpfxrng[0],/remove_all) eq '' then print,'ALL' polystr='' yfit=fltarr(n_elements(xs[l,*])) for j=0,gpforder do begin polystr=polystr+strcompress(gpfcoeff[j])+' * X ^'+strcompress(j) if j ne gpforder then polystr=polystr+' +' yfit=yfit+gpfcoeff[j]*xs[l,*]^j endfor print,'Y ='+polystr if soro eq 0 then oplot,xs[l,*],yfit+ay[l],linestyle=2,color=get_color(0,255,0) else oplot,xs[l,*],yfit,linestyle=2,color=get_color(0,255,0) openw,4,'polyfit.gp',/append printf,4,files[l] printf,4,'Coefficients: '+polystr printf,4,'Range for fitting: ',gpfxrng close,4 endfor endif end pro gpfitabs,files,tt,st,xt,yt,xmin,xmax,ymin,ymax,ytick,off,lab,chsz,dl,cut,soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys,draw gpfuval='' listcheck,files savefits='' readdata,files,tt,st,xt,yt,xmin,xmax,ymin,ymax,ytick,off,lab,chsz,dl,cut,soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys makeplot,files,tt,st,xt,yt,xmin,xmax,ymin,ymax,ytick,off,lab,chsz,dl,cut,soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gatorplotvars.dat' n=n_elements(files) gpfmenu=widget_base(xsize=260,ysize=450,title='Absorption Fit') labelgpfmain=widget_label(gpfmenu,value='Fit absorption lines') labelgpfrange=widget_label(gpfmenu,value='Range(s):',yoffset=20) gpfrange=widget_text(gpfmenu,xsize=22,ysize=4,/editable,/all_events,yoffset=40,uvalue='gpfrange') labelgpfng=widget_label(gpfmenu,value='# Gauss:',yoffset=20,xoffset=160) gpfng=widget_text(gpfmenu,xsize=2,/editable,/all_events,yoffset=37,xoffset=160,uvalue='gpfng') labelgpfnl=widget_label(gpfmenu,value='# lines:',yoffset=20,xoffset=210) gpfnl=widget_text(gpfmenu,xsize=2,/editable,/all_events,yoffset=37,xoffset=210,uvalue='gpfnl') labelgpfcnst=widget_label(gpfmenu,value='Constant:',yoffset=66,xoffset=160) gpfcnst=widget_text(gpfmenu,xsize=5,/editable,/all_events,yoffset=82,xoffset=160,uvalue='gpfcnst') gpfwt=cw_bgroup(gpfmenu,['None','Poisson'],yoffset=115,/column,/frame,/exclusive,label_top='Weighting:',uvalue='gpfrange',set_value=0) labelgpfoutf=widget_label(gpfmenu,value='Output (.gpfit) File:',xoffset=95,yoffset=116) gpfoutf=widget_text(gpfmenu,xsize=12,/editable,/all_events,xoffset=95,yoffset=132,uvalue='gpfoutf') labelgpfpltf=widget_label(gpfmenu,value='Plot (.dat) File:',xoffset=95,yoffset=164) gpfpltf=widget_text(gpfmenu,xsize=12,/editable,/all_events,xoffset=95,yoffset=180,uvalue='gpfpltf') labelgpfinf=widget_label(gpfmenu,value='Input file:',yoffset=225) gpfinf=widget_text(gpfmenu,xsize=12,/editable,/all_event,xoffset=80,yoffset=215,uvalue='gpfinf') gpfbrws=widget_button(gpfmenu,value='Browse',yoffset=218,xoffset=175,uvalue='gpfbrws') lablegpfpars=widget_label(gpfmenu,value='or Enter Fit Parameters:',yoffset=248) gpfpars=widget_text(gpfmenu,xsize=25,ysize=10,/editable,/all_events,yoffset=265,uvalue='gpfpars') gpfok=widget_button(gpfmenu,value='Fit',yoffset=420,uvalue='gpfok') gpfcancel=widget_button(gpfmenu,value='Cancel',yoffset=420,xoffset=75,uvalue='gpfcancel') widget_control,gpfmenu,set_uvalue=[gpfrange,gpfng,gpfnl,gpfcnst,gpfwt,gpfoutf,gpfpltf,gpfinf,gpfpars] widget_control,gpfmenu,/realize while gpfuval ne 'gpfok' and gpfuval ne 'gpfcancel' do begin gpfev=widget_event([gpfmenu,draw]) widget_control,gpfev.id,get_uvalue=gpfuval if gpfuval eq 'draw' then begin cursor,xc,yc,/nowait,/data if gpfev.press eq 1 then xran1=xc if gpfev.release eq 1 then begin widget_control,gpfrange,get_value=gpfrcurr if strcompress(gpfrcurr[0],/remove_all) eq '' then begin widget_control,gpfrange,set_value=strcompress(xran1,/remove_all)+strcompress(xc) endif else widget_control,gpfrange,set_value=strcompress(xran1,/remove_all)+strcompress(xc),/append endif endif if gpfuval eq 'gpfbrws' then begin gpffl=dialog_pickfile() widget_control,gpfinf,set_value=gpffl endif endwhile widget_control,gpfev.top,get_uvalue=gpft widget_control,gpft[0],get_value=gpfxrng widget_control,gpft[1],get_value=gpfngauss widget_control,gpft[2],get_value=gpfnlines widget_control,gpft[3],get_value=gpfconst widget_control,gpft[4],get_value=gpfwght widget_control,gpft[5],get_value=gpfoutfl widget_control,gpft[6],get_value=gpfpltfl widget_control,gpft[7],get_value=gpfinfl widget_control,gpft[8],get_value=gpfparams widget_control,gpfev.top,/DESTROY if gpfuval eq 'gpfok' then begin gpfconst=gpfconst[0]+0. for l=0,n-1 do begin gpfn=0 if strcompress(gpfinfl,/remove_all) ne '' then begin close,3 openr,3,gpfinfl readf,3,ngauss readf,3,nlines P=fltarr(ngauss*3+nlines*5,3) for j=0,ngauss*3+nlines*5-1 do begin readf,3,gpfax,gpfay,gpfaz P[j,0]=gpfax P[j,1]=gpfay P[j,2]=gpfaz if gpfay eq 0 then gpfn=gpfn+1 endfor close,3 endif else begin ngauss=gpfngauss[0]+0 nlines=gpfnlines[0]+0 P=fltarr(ngauss*3+nlines*5,3) for j=0,ngauss*3+nlines*5-1 do begin P[j,0]=strparse(gpfparams[j],1)+0. P[j,1]=strparse(gpfparams[j],2)+0. P[j,2]=strparse(gpfparams[j],3)+0. if P[j,1] eq 0 then gpfn=gpfn+1 endfor endelse B=fltarr(gpfn) for j=0,ngauss-1 do begin P[j*3+2,0]=P[j*3+2,0]*P[j*3+1,0]/(3.e+5*2*sqrt(2*alog(2))) P[j*3,0]=P[j*3,0]/(P[j*3+2,0]*2.5) endfor gpfn=0 for j=0,ngauss*3+nlines*5-1 do begin if P[j,1] eq 0 then begin B[gpfn]=j gpfn=gpfn+1 endif endfor getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif save,P,B,ngauss,nlines,filename=varsdir+'/gpfitvars.dat' if strcompress(gpfxrng[0],/remove_all) eq '' then xfit=findgen(n_elements(xs[l,*])) else begin xrng1=strparse(gpfxrng[0],1)+0. xrng2=strparse(gpfxrng[0],2)+0. xfit=where(xs[l,*] ge xrng1 AND xs[l,*] le xrng2) if n_elements(gpfxrng) gt 1 then for j=1,n_elements(gpfxrng)-1 do begin xrng1=strparse(gpfxrng[j],1)+0. xrng2=strparse(gpfxrng[j],2)+0. xfit=[xfit,where(xs[l,*] ge xrng1 AND xs[l,*] le xrng2)] endfor endelse gpfxs=fltarr(n_elements(xfit)) gpfys=fltarr(n_elements(xfit)) gpfxs[*]=xs[l,xfit] gpfys[*]=ys[l,xfit]-gpfconst if gpfwght eq 0 then weights=fltarr(n_elements(xfit))+1 if gpfwght eq 1 then weights=abs(1./gpfys) gpfcoeff=P[B,0] gpffit=curvefit(gpfxs,gpfys,weights,gpfcoeff,sigma,function_name='multabsfit',itmax=100) P[B,0]=gpfcoeff for j=0,ngauss*3-1 do begin if P[j,1] gt 0 then begin if j MOD 3 eq 1 then P[j,0] = P[j,1]*P[P[j,2],0] if j MOD 3 eq 2 then P[j,0] = P[j,1]*P[P[j,2],0]*P[j-1,0]/P[P[j,2]-1,0] endif if P[j,1] lt 0 and P[j,1] ne -1 then begin tabs=abs(P[j,1]) tnum=floor(tabs) tden=floor(abs(100*(tabs-floor(tabs)))+.1) tscl=P[tnum,0]/P[tden,0] if j MOD 3 eq 1 then P[j,0] = tscl*P[P[j,2],0] if j MOD 3 eq 2 then P[j,0] = tscl*P[P[j,2],0]*P[j-1,0]/P[P[j,2]-1,0] endif endfor for j=0,ngauss*3-1 do begin if P[j,1] gt 0 then begin if j MOD 3 eq 0 then P[j,0]=P[j,1]*P[P[j,2],0]*P[P[j,2]+2,0]/P[j+2,0] endif if P[j,1] lt 0 and P[j,1] ne -1 then begin tabs=abs(P[j,1]) tnum=floor(tabs) tden=floor(abs(100*(tabs-floor(tabs)))+.1) tscl=P[tnum,0]/P[tden,0] if j MOD 3 eq 0 then tscl=tscl*P[tnum+2,0]/P[tden+2,0] if j MOD 3 eq 0 then P[j,0]=tscl*P[P[j,2],0]*P[P[j,2]+2,0]/P[j+2,0] endif endfor for j=ngauss*3,ngauss*3+nlines*5-1 do begin if P[j,1] gt 0 then begin if (j-ngauss*3) MOD 5 eq 1 then P[j,0] = P[j,1]*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 2 then P[j,0] = P[j,1]*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 0 then P[j,0] = P[j,1]*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 3 then P[j,0] = P[j,1]*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 4 then P[j,0] = P[j,1]*P[P[j,2],0] endif if P[j,1] lt 0 and P[j,1] ne -1 then begin tabs=abs(P[j,1]) tnum=floor(tabs) tden=floor(abs(100*(tabs-floor(tabs)))+.1) tscl=P[tnum,0]/P[tden,0] if (j-ngauss*3) MOD 5 eq 1 then P[j,0] = tscl*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 2 then P[j,0] = tscl*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 0 then P[j,0] = tscl*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 3 then P[j,0] = tscl*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 4 then P[j,0] = tscl*P[P[j,2],0] endif if (j-ngauss*3) MOD 5 eq 0 then P[j,0] = P[j,0] > 0.0 if (j-ngauss*3) MOD 5 eq 4 then P[j,0] = P[j,0] < 1.0 endfor gpfxs=fltarr(n_elements(xs[l,*])) gpfxs[*]=xs[l,*] gpfG=fltarr(ngauss+nlines,n_elements(gpfxs)) gpffit=fltarr(ngauss+nlines,5) for j=0,ngauss-1 do begin Z=(gpfxs-P[j*3+1,0])/P[j*3+2,0] gpfG[j,*]=P[j*3,0]*exp(-Z^2/2) gpffit[j,0]=total(gpfG[j,*])*(gpfxs[1]-gpfxs[0]) gpffit[j,1]=P[j*3+1,0] gpffit[j,2]=abs(P[j*3+2,0]*2*sqrt(2*alog(2)))*3.e+5/P[j*3+1,0] endfor for j=ngauss,ngauss+nlines-1 do begin Z=(gpfxs-P[ngauss*3+(j-ngauss)*5+1,0])/P[ngauss*3+(j-ngauss)*5+2,0] tau=P[ngauss*3+(j-ngauss)*5,0]*exp(-Z^2) gpfG[j,*]=P[ngauss*3+(j-ngauss)*5+4,0]*P[ngauss*3+(j-ngauss)*5+3,0]*exp(-tau)+P[ngauss*3+(j-ngauss)*5+3,0]*(1-P[ngauss*3+(j-ngauss)*5+4,0]) gpffit[j,0]=P[ngauss*3+(j-ngauss)*5,0] gpffit[j,1]=P[ngauss*3+(j-ngauss)*5+1,0] gpffit[j,2]=P[ngauss*3+(j-ngauss)*5+2,0] gpffit[j,3]=P[ngauss*3+(j-ngauss)*5+3,0] gpffit[j,4]=P[ngauss*3+(j-ngauss)*5+4,0] endfor print,'Multiple Absorption line fit to '+files[l] print,'X-axis ranges used in calculating the fit:' for j=0,n_elements(gpfxrng)-1 do print,gpfxrng[j] if strcompress(gpfxrng[0],/remove_all) eq '' then print,'ALL' print,'Parameters (flux, wavelength, FWHM):' for j=0,ngauss-1 do print,j+1,gpffit[j,0],gpffit[j,1],gpffit[j,2] print,'Parameters (Tau_0, wavelength, lambda_D, I_0, C_f):' for j=ngauss,ngauss+nlines-1 do print,j+1,gpffit[j,0],gpffit[j,1],gpffit[j,2],gpffit[j,3],gpffit[j,4] if strcompress(gpfoutfl[0],/remove_all) eq '' then begin gpfoutfl='multabsfit.gpfit' endif else gpfoutfl=gpfoutfl[0] if strcompress(gpfpltfl[0],/remove_all) eq '' then begin gpfpltfl='gpmultabsfit.dat' endif else gpfpltfl=gpfpltfl[0] openw,4,gpfoutfl,/append printf,4,'Multiple Absorption fit to '+files[l] printf,4,'X-axis ranges used in calculating the fit:' for j=0,n_elements(gpfxrng)-1 do printf,4,gpfxrng[j] if strcompress(gpfxrng[0],/remove_all) eq '' then printf,4,'ALL' printf,4,'Parameters (flux, wavelength, FWHM):' for j=0,ngauss-1 do printf,4,j+1,gpffit[j,0],gpffit[j,1],gpffit[j,2] printf,4,'Parameters (Tau_0, wavelength, lambda_D, I_0, C_f):' for j=ngauss,ngauss+nlines-1 do printf,4,j+1,gpffit[j,0],gpffit[j,1],gpffit[j,2],gpffit[j,3],gpffit[j,4] close,4 gpfplot=fltarr(ngauss+nlines+3,n_elements(gpfxs)) gpfplot[0,*]=gpfxs gpftotfit=fltarr(n_elements(gpfxs))+gpfconst gpfplot[2,*]=gpftotfit for j=0,ngauss-1 do begin gpfplot[j+3,*]=gpfG[j,*] gpftotfit=gpftotfit+gpfG[j,*] endfor for j=ngauss,ngauss+nlines-1 do begin gpfplot[j+3,*]=gpfG[j,*] gpftotfit=gpftotfit+gpfG[j,*] gpftotfit=gpftotfit-P[ngauss*3+(j-ngauss)*5+3,0] endfor gpfplot[1,*]=gpftotfit openw,4,gpfpltfl gpfstrout='' for j=0,ngauss+nlines+2 do begin gpfstrout=gpfstrout+strcompress(gpfplot[j,*]) endfor printf,4,gpfstrout close,4 gpcolors=[get_color(255,0,0),get_color(0,255,0),get_color(0,0,255),get_color(255,160,0),get_color(255,0,255)] if soro eq 0 then begin for j=0,ngauss+nlines-1 do oplot,xs[l,*],gpfG[j,*]+ay[l],color=gpcolors[j MOD 5],linestyle=2 oplot,xs[l,*],gpftotfit+ay[l],color=get_color(0,255,255) endif else begin for j=0,ngauss+nlines-1 do oplot,xs[l,*],gpfG[j,*],color=gpcolors[j MOD 5],linestyle=2 oplot,xs[l,*],gpftotfit,color=get_color(0,255,255) endelse endfor endif file_delete,varsdir+'/gpfitvars.dat',/quiet end pro gpfitud,files,tt,st,xt,yt,xmin,xmax,ymin,ymax,ytick,off,lab,chsz,dl,cut,soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys,draw gpfuval='' listcheck,files savefits='' readdata,files,tt,st,xt,yt,xmin,xmax,ymin,ymax,ytick,off,lab,chsz,dl,cut,soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys makeplot,files,tt,st,xt,yt,xmin,xmax,ymin,ymax,ytick,off,lab,chsz,dl,cut,soro,savefits,usep,xll,yll,axcol,aycol,usecolor,lstyle,smthar,xs,ys getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gatorplotvars.dat' n=n_elements(files) gpfmenu=widget_base(xsize=240,ysize=470,title='User Defined Fit') labelgpfmain=widget_label(gpfmenu,value='Fit a user-defined function') labelgpfname=widget_label(gpfmenu,value='Function name (one word):',yoffset=20) gpfname=widget_text(gpfmenu,xsize=20,/editable,/all_events,yoffset=40,uvalue='gpfname') labelgpffun=widget_label(gpfmenu,value='Function of X and params A[0],A[1],...',yoffset=70) labelgpffun2=widget_label(gpfmenu,value='Ex: A[0]*sin(A[1]*X)+A[2]*X',yoffset=90) gpffun=widget_text(gpfmenu,xsize=26,/editable,/all_events,yoffset=110,uvalue='gpffun') labelgpfpds=widget_label(gpfmenu,value='Partial Derivatives as functions of X',yoffset=140) labelgpfpds2=widget_label(gpfmenu,value='Ex: sin(A[1]*X) is 1st partial above',yoffset=160) gpfpds=widget_text(gpfmenu,xsize=26,ysize=3,/editable,/all_events,yoffset=180,uvalue='gpfpds') labelgpfrange=widget_label(gpfmenu,value='Range(s):',yoffset=250) gpfrange=widget_text(gpfmenu,xsize=22,ysize=4,/editable,/all_events,yoffset=270,uvalue='gpfrange') gpfwt=cw_bgroup(gpfmenu,['None','Poisson'],yoffset=340,/column,/frame,/exclusive,label_top='Weighting:',uvalue='gpfrange',set_value=0) labelgpfinit=widget_label(gpfmenu,value='Init. guesses for params:',xoffset=85,yoffset=344) gpfinit=widget_text(gpfmenu,xsize=8,ysize=3,/editable,/all_events,xoffset=95,yoffset=365,uvalue='gpfinit') gpfok=widget_button(gpfmenu,value='Fit',yoffset=440,uvalue='gpfok') gpfcancel=widget_button(gpfmenu,value='Cancel',yoffset=440,xoffset=75,uvalue='gpfcancel') widget_control,gpfmenu,set_uvalue=[gpfname,gpffun,gpfpds,gpfrange,gpfwt,gpfinit] widget_control,gpfmenu,/realize while gpfuval ne 'gpfok' and gpfuval ne 'gpfcancel' do begin gpfev=widget_event([gpfmenu,draw]) widget_control,gpfev.id,get_uvalue=gpfuval if gpfuval eq 'draw' then begin cursor,xc,yc,/nowait,/data if gpfev.press eq 1 then xran1=xc if gpfev.release eq 1 then begin widget_control,gpfrange,get_value=gpfrcurr if strcompress(gpfrcurr[0],/remove_all) eq '' then begin widget_control,gpfrange,set_value=strcompress(xran1,/remove_all)+strcompress(xc) endif else widget_control,gpfrange,set_value=strcompress(xran1,/remove_all)+strcompress(xc),/append endif endif endwhile widget_control,gpfev.top,get_uvalue=gpft widget_control,gpft[0],get_value=gpfpname widget_control,gpft[1],get_value=gpffunct widget_control,gpft[2],get_value=gpfpders widget_control,gpft[3],get_value=gpfxrng widget_control,gpft[4],get_value=gpfwght widget_control,gpft[5],get_value=gpfcoeff widget_control,gpfev.top,/DESTROY if gpfuval eq 'gpfok' then begin openw,4,gpfpname+'.pro' printf,4,'PRO '+gpfpname+',X, A, F, pder' printf,4,' F = '+gpffunct pderstr=' IF N_PARAMS() GE 4 then pder=[['+gpfpders[0]+']' for j=1,n_elements(gpfpders)-1 do pderstr=pderstr+',['+gpfpders[j]+']' pderstr=pderstr+']' printf,4,pderstr printf,4,'END' close,4 for l=0,n-1 do begin if strcompress(gpfxrng[0],/remove_all) eq '' then xfit=findgen(n_elements(xs[l,*])) else begin xrng1=strparse(gpfxrng[0],1)+0. xrng2=strparse(gpfxrng[0],2)+0. xfit=where(xs[l,*] ge xrng1 AND xs[l,*] le xrng2) if n_elements(gpfxrng) gt 1 then for j=1,n_elements(gpfxrng)-1 do begin xrng1=strparse(gpfxrng[j],1)+0. xrng2=strparse(gpfxrng[j],2)+0. xfit=[xfit,where(xs[l,*] ge xrng1 AND xs[l,*] le xrng2)] endfor endelse gpfcoeff=gpfcoeff+0. gpfxs=fltarr(n_elements(xfit)) gpfys=fltarr(n_elements(xfit)) gpfxs[*]=xs[l,xfit] gpfys[*]=ys[l,xfit] if gpfwght eq 0 then weights=fltarr(n_elements(xfit))+1 if gpfwght eq 1 then weights=1./gpfys gpffit=curvefit(gpfxs,gpfys,weights,gpfcoeff,sigma,function_name=gpfpname[0],itmax=100) print,'User-defined fit to '+files[l] print,'X-axis ranges used in calculating the fit:' for j=0,n_elements(gpfxrng)-1 do print,gpfxrng[j] if strcompress(gpfxrng[0],/remove_all) eq '' then print,'ALL' print,'Function: '+gpffunct print,'Coefficients:' for j=0,n_elements(gpfcoeff)-1 do print,'A['+strcompress(j,/remove_all)+']: '+string(gpfcoeff[j]) if soro eq 0 then oplot,gpfxs,gpffit+ay[l],linestyle=1 else oplot,gpfxs,gpffit,linestyle=1 openw,4,'udfit.gp',/append printf,4,files[l] printf,4,'Function: '+gpffunct printf,4,'Coefficients: ' for j=0,n_elements(gpfcoeff)-1 do printf,4,'A['+strcompress(j,/remove_all)+']: '+string(gpfcoeff[j]) printf,4,'Range for fitting: ',gpfxrng close,4 endfor endif end pro gphelp f='' qt=-1 a$='' browser=0 getgpconfig,cfgexists,gpcfg helpdir='$IDL_DIR/contrib/astroLib/text/gatorplot.help' if cfgexists eq 1 then begin helpdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'HELP')],10,150) helpdir=strcompress(helpdir[0],/remove_all) endif if cfgexists eq 1 AND n_elements(gpcfg) gt 3 then begin lweb=strmid(gpcfg[where(strmid(gpcfg,0,3) eq 'WEB')],10,150) lweb=strcompress(lweb[0],/remove_all) if lweb ne '' AND lweb ne 'TEXT' then browser=1 endif if browser eq 0 then begin openr,1,helpdir while NOT EOF(1) AND qt ne 0 do begin for j=0,22 do begin if NOT EOF(1) then begin readf,1,f print,f endif endfor while a$ ne ' ' AND a$ ne 'q' do a$=get_kbrd(1) if a$ eq 'q' then qt=0 a$='' endwhile print,'DONE' close,1 endif else begin lweb=lweb+' http://www.astro.ufl.edu/~warner/GatorPlot/ &' spawn,lweb endelse end pro getgpconfig,cfgexists,gpcfg cfgexists=0 if file_test('$HOME/.gatorplot') eq 1 then begin openr,1,'$HOME/.gatorplot' gpcfg=strarr(3) readf,1,gpcfg IF NOT EOF(1) then begin gpweb='' readf,1,gpweb gpcfg=[gpcfg,gpweb] ENDIF close,1 cfgexists=1 endif else begin if file_test('$GATORPLOT/.gatorplot') eq 1 then begin openr,1,'$GATORPLOT/.gatorplot' gpcfg=strarr(3) readf,1,gpcfg IF NOT EOF(1) then begin gpweb='' readf,1,gpweb gpcfg=[gpcfg,gpweb] ENDIF close,1 cfgexists=1 endif endelse end function get_color,r,g,b return,r+g*256.+b*65536. end function strparse,s,x s2=s if N_PARAMS() eq 1 then x=1 if n_elements(s) eq 1 then parsed='' else parsed=strarr(n_elements(s)) for j=0,n_elements(s)-1 do begin s[j]=strcompress(s[j]) n=0 p2=0 e=0 while n lt x do begin p1=p2 if p1 eq -1 then e=1 p2=strpos(s[j],' ',p1+1) n=n+1 endwhile if p2 eq -1 then p2=strlen(s[j]) parsed[j]=strcompress(strmid(s[j],p1,p2-p1),/remove_all) if e eq 1 then parsed[j]='' endfor s=s2 return,parsed end PRO plaw, X, A, F, pder F = A[0]*X^A[1] IF N_PARAMS() GE 4 then pder=[[X^A[1]] ,[A[0]*X^A[1]*alog(X)]] END pro multgauss,X,A,F,pder getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpfitvars.dat' n=n_elements(B) np=n_elements(P[*,0]) for j=0,n-1 do P[B[j],0] = A[j] for j=0,np-1 do begin if P[j,1] gt 0 then begin if j MOD 3 eq 1 then P[j,0] = P[j,1]*P[P[j,2],0] if j MOD 3 eq 2 then P[j,0] = P[j,1]*P[P[j,2],0]*P[j-1,0]/P[P[j,2]-1,0] endif if P[j,1] lt 0 and P[j,1] ne -1 then begin tabs=abs(P[j,1]) tnum=floor(tabs) tden=floor(abs(100*(tabs-floor(tabs)))+.1) tscl=P[tnum,0]/P[tden,0] if j MOD 3 eq 1 then P[j,0] = tscl*P[P[j,2],0] if j MOD 3 eq 2 then P[j,0] = tscl*P[P[j,2],0]*P[j-1,0]/P[P[j,2]-1,0] endif endfor for j=0,np-1 do begin if P[j,1] gt 0 then begin if j MOD 3 eq 0 then P[j,0]=P[j,1]*P[P[j,2],0]*P[P[j,2]+2,0]/P[j+2,0] endif if P[j,1] lt 0 and P[j,1] ne -1 then begin tabs=abs(P[j,1]) tnum=floor(tabs) tden=floor(abs(100*(tabs-floor(tabs)))+.1) tscl=P[tnum,0]/P[tden,0] if j MOD 3 eq 0 then tscl=tscl*P[tnum+2,0]/P[tden+2,0] if j MOD 3 eq 0 then P[j,0]=tscl*P[P[j,2],0]*P[P[j,2]+2,0]/P[j+2,0] endif if j MOD 3 eq 0 AND P[j,0] le 0.0 then P[j,0] = 0.1 endfor F=fltarr(n_elements(X)) for j=0,ngauss-1 do begin Z=(X-P[j*3+1,0])/P[j*3+2,0] F=F+P[j*3,0]*exp(-Z^2/2) endfor IF N_PARAMS() GE 4 then begin pder=fltarr(n_elements(X),n) for j=0,n-1 do begin if B[j] MOD 3 eq 0 then begin Z=(X-P[B[j]+1,0])/P[B[j]+2,0] pder[*,j]=exp(-Z^2/2) endif if B[j] MOD 3 eq 1 then begin Z=(X-P[B[j],0])/P[B[j]+1,0] pder[*,j]=P[B[j]-1,0]*exp(-Z^2/2)*(X-P[B[j],0])/P[B[j]+1,0]^2 endif if B[j] MOD 3 eq 2 then begin Z=(X-P[B[j]-1,0])/P[B[j],0] pder[*,j]=P[B[j]-2,0]*exp(-Z^2/2)*(X-P[B[j]-1,0])^2/P[B[j],0]^3 endif endfor endif end pro poly, X, A, F, pder order=n_elements(A)-1 F=fltarr(n_elements(X)) for j=0,order do begin F=F+A[j]*X^j endfor IF N_PARAMS() GE 4 then begin pder=fltarr(n_elements(X),order+1) for j=0,order do begin pder[*,j]=X^j endfor endif end pro multabsfit,X,A,F,pder getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpfitvars.dat' n=n_elements(B) np=ngauss*3 for j=0,n-1 do P[B[j],0] = A[j] for j=0,np-1 do begin if P[j,1] gt 0 then begin if j MOD 3 eq 1 then P[j,0] = P[j,1]*P[P[j,2],0] if j MOD 3 eq 2 then P[j,0] = P[j,1]*P[P[j,2],0]*P[j-1,0]/P[P[j,2]-1,0] endif if P[j,1] lt 0 and P[j,1] ne -1 then begin tabs=abs(P[j,1]) tnum=floor(tabs) tden=floor(abs(100*(tabs-floor(tabs)))+.1) tscl=P[tnum,0]/P[tden,0] if j MOD 3 eq 1 then P[j,0] = tscl*P[P[j,2],0] if j MOD 3 eq 2 then P[j,0] = tscl*P[P[j,2],0]*P[j-1,0]/P[P[j,2]-1,0] endif endfor for j=0,np-1 do begin if P[j,1] gt 0 then begin if j MOD 3 eq 0 then P[j,0]=P[j,1]*P[P[j,2],0]*P[P[j,2]+2,0]/P[j+2,0] endif if P[j,1] lt 0 and P[j,1] ne -1 then begin tabs=abs(P[j,1]) tnum=floor(tabs) tden=floor(abs(100*(tabs-floor(tabs)))+.1) tscl=P[tnum,0]/P[tden,0] if j MOD 3 eq 0 then tscl=tscl*P[tnum+2,0]/P[tden+2,0] if j MOD 3 eq 0 then P[j,0]=tscl*P[P[j,2],0]*P[P[j,2]+2,0]/P[j+2,0] endif endfor np=ngauss*3+nlines*5 for j=ngauss*3,np-1 do begin if P[j,1] gt 0 then begin if (j-ngauss*3) MOD 5 eq 1 then P[j,0] = P[j,1]*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 2 then P[j,0] = P[j,1]*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 0 then P[j,0] = P[j,1]*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 3 then P[j,0] = P[j,1]*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 4 then P[j,0] = P[j,1]*P[P[j,2],0] endif if P[j,1] lt 0 and P[j,1] ne -1 then begin tabs=abs(P[j,1]) tnum=floor(tabs) tden=floor(abs(100*(tabs-floor(tabs)))+.1) tscl=P[tnum,0]/P[tden,0] if (j-ngauss*3) MOD 5 eq 1 then P[j,0] = tscl*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 2 then P[j,0] = tscl*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 0 then P[j,0] = tscl*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 3 then P[j,0] = tscl*P[P[j,2],0] if (j-ngauss*3) MOD 5 eq 4 then P[j,0] = tscl*P[P[j,2],0] endif if (j-ngauss*3) MOD 5 eq 0 AND P[j,0] le 0.0 then P[j,0] = 0.05 if (j-ngauss*3) MOD 5 eq 4 AND P[j,0] ge 1.0 then P[j,0] = 0.95 endfor F=fltarr(n_elements(X)) for j=0,ngauss-1 do begin Z=(X-P[j*3+1,0])/P[j*3+2,0] F=F+P[j*3,0]*exp(-Z^2/2) endfor for j=0,nlines-1 do begin Z=(X-P[ngauss*3+j*5+1,0])/P[ngauss*3+j*5+2,0] tau=P[ngauss*3+j*5,0]*exp(-Z^2) F=F+P[ngauss*3+j*5+4,0]*P[ngauss*3+j*5+3,0]*exp(-tau)+P[ngauss*3+j*5+3,0]*(1-P[ngauss*3+j*5+4,0]) F=F-P[ngauss*3+j*5+3,0] endfor IF N_PARAMS() GE 4 then begin pder=fltarr(n_elements(X),n) for j=0,n-1 do begin if B[j] lt ngauss*3 then begin if B[j] MOD 3 eq 0 then begin Z=(X-P[B[j]+1,0])/P[B[j]+2,0] pder[*,j]=exp(-Z^2/2) endif if B[j] MOD 3 eq 1 then begin Z=(X-P[B[j],0])/P[B[j]+1,0] pder[*,j]=P[B[j]-1,0]*exp(-Z^2/2)*(X-P[B[j],0])/P[B[j]+1,0]^2 endif if B[j] MOD 3 eq 2 then begin Z=(X-P[B[j]-1,0])/P[B[j],0] pder[*,j]=P[B[j]-2,0]*exp(-Z^2/2)*(X-P[B[j]-1,0])^2/P[B[j],0]^3 endif endif else begin if (B[j]-ngauss*3) MOD 5 eq 0 then begin Z=(X-P[B[j]+1,0])/P[B[j]+2,0] tau=P[B[j],0]*exp(-Z^2) pder[*,j]=-P[B[j]+4,0]*P[B[j]+3,0]*exp(-tau)*exp(-Z^2) endif if (B[j]-ngauss*3) MOD 5 eq 1 then begin Z=(X-P[B[j],0])/P[B[j]+1,0] tau=P[B[j-1],0]*exp(-Z^2) pder[*,j]=-P[B[j]+3,0]*P[B[j]+2,0]*exp(-tau)*P[B[j]-1,0]*exp(-Z^2)*(X-P[B[j],0])/P[B[j]+1,0]^2 endif if (B[j]-ngauss*3) MOD 5 eq 2 then begin Z=(X-P[B[j]-1,0])/P[B[j],0] tau=P[B[j-2],0]*exp(-Z^2) pder[*,j]=-P[B[j]+2,0]*P[B[j]+1,0]*exp(-tau)*P[B[j]-2,0]*exp(-Z^2)*(X-P[B[j]-1,0])^2/P[B[j],0]^3 endif if (B[j]-ngauss*3) MOD 5 eq 3 then begin Z=(X-P[B[j]-2,0])/P[B[j]-1,0] tau=P[B[j]-3,0]*exp(-Z^2) pder[*,j]=P[B[j]+1,0]*exp(-tau)+1-P[B[j]+1,0] endif if (B[j]-ngauss*3) MOD 5 eq 4 then begin Z=(X-P[B[j]-3,0])/P[B[j]-2,0] tau=P[B[j]-4,0]*exp(-Z^2) pder[*,j]=P[B[j]-1,0]*exp(-tau)-P[B[j]-1,0] endif endelse endfor endif end pro gpscript,gpsfile,args getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif save, /variables, filename=varsdir+'/gpscriptvars.dat' if n_elements(args) eq 0 then call_procedure,gpsfile else call_procedure,gpsfile,args file_delete,varsdir+'/gpscriptvars.dat',/quiet end pro gpsload,files,xcol=nxcol,ycol=nycol,funmin=fmin,funmax=fmax,funpts=fpts,mspec=mspec COMMON shared,smspec smspec = mspec n=n_elements(files) nmax=0 xc=strarr(n) yc=strarr(n) linskp=strarr(n) linskz=0 colsame=0 fsame=0 if n_elements(nxcol) ne 0 then nxcol=string(nxcol) else nxcol='' if n_elements(nycol) ne 0 then nycol=string(nycol) xcz='' ycz='' nrows = 0 for j=0,n-1 do begin if strmid(files[j],0,4) eq 'f(x)' then begin if n_elements(fpts) eq 0 AND nmax gt 0 then begin fpts=nmax fmin=x[0] fmax=x[nmax-1] endif funst='y='+strmid(files[j],5,strlen(files[j])-5) x=findgen(fpts)*(fmax-fmin)/(fpts-1)+fmin fxt=execute(funst) endif else if strpos(strlowcase(files[j]),'.fit') ne -1 then begin fitsplot,files[j],x,y sz = size(y) if sz[0] ne 1 then begin nrows = nrows + sz[2] endif else nrows = nrows + 1 endif else begin if n_elements(nxcol) ge j+1 then axcol=nxcol[j] else axcol=nxcol[0] if n_elements(nycol) ge j+1 then aycol=nycol[j] else aycol=nycol[0] asciiplot,files[j],x,y,xcz,ycz,linskz,colsame,axcol,aycol endelse xc[j]=xcz yc[j]=ycz linskp[j]=linskz nmax=nmax > n_elements(x) endfor xs=fltarr(nrows,nmax) ys=fltarr(nrows,nmax) xs[*]=-1 irow = 0 for j=0,n-1 do begin if strmid(files[j],0,4) eq 'f(x)' then begin funst='y='+strmid(files[j],5,strlen(files[j])-5) x=findgen(fpts)*(fmax-fmin)/(fpts-1)+fmin fxt=execute(funst) endif else if strpos(strlowcase(files[j]),'.fit') ne -1 then begin fitsplot,files[j],x,y endif else begin if n_elements(nxcol) ge j+1 then axcol=nxcol[j] else axcol=nxcol[0] if n_elements(nycol) ge j+1 then aycol=nycol[j] else aycol=nycol[0] asciiplot,files[j],x,y,xcz,ycz,linskz,colsame,axcol,aycol endelse szy=size(y) if szy[0] eq 1 then begin xs[irow,0:n_elements(x)-1]=x ys[irow,0:n_elements(x)-1]=y irow = irow+1 endif else begin for l=0,szy[2]-1 do begin xs[irow,0:n_elements(x)-1]=x ys[irow,0:n_elements(x)-1]=y[*,l,0] irow = irow+1 endfor endelse endfor n = nrows getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif save, /variables, filename=varsdir+'/gpscriptvars.dat' end pro gpsmultiplot,rows,cols,auto=mpauto getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpscriptvars.dat' !p.multi=[0,rows,cols] if n_elements(mpauto) eq 0 then mpauto=0 save, /variables, filename=varsdir+'/gpscriptvars.dat' end pro gpsplot,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,xtitle=xt,ytitle=yt,title=t,xlog=xlog,ylog=ylog,overplot=op,charsize=cs,linestyle=ls,color=clr,psym=ps,offset=off,label=lbl,xmargin=xmgn,ymargin=ymgn getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpscriptvars.dat' if n_elements(xt) eq 0 then xt='' if n_elements(yt) eq 0 then yt='' if n_elements(t) eq 0 then t='' if n_elements(xlog) eq 0 then xlog=0 if n_elements(ylog) eq 0 then ylog=0 if n_elements(op) eq 0 then soro=0 else soro=1 if n_elements(cs) eq 0 then cs=1 if n_elements(xmgn) ne 0 then !x.margin=xmgn if n_elements(ymgn) ne 0 then !y.margin=ymgn ay=fltarr(n) ay[0]=0 noff=n_elements(off) nlbl=n_elements(lbl) for j=1,n-1 do begin ayz=max(ys[j-1,*]) if j le noff then begin if strcompress(off[j-1],/remove_all) ne '' then ay[j]=off[j-1]+0.0 else ay[j]=ay[j-1]+floor(10.^ceil(alog10(1./ayz))*ayz+.99)/10.^ceil(alog10(1./ayz)) endif else begin ay[j]=ay[j-1]+floor(10.^ceil(alog10(1./ayz))*ayz+.99)/10.^ceil(alog10(1./ayz)) endelse endfor if n_elements(xmin) eq 0 then xmin=min(xs) if n_elements(xmax) eq 0 then xmax=max(xs) if n_elements(ymin) eq 0 then if soro eq 0 then ymin=min(ys[0,where(xs[0,*] ge xmin AND xs[0,*] le xmax)]) else ymin=min(ys[where(xs ge xmin AND xs le xmax)]) if n_elements(ymax) eq 0 then begin if soro eq 1 then ymax=max(ys[where(xs ge xmin AND xs le xmax)]) else ymax=ay[n-1]+max(ys[n-1,where(xs[n-1,*] ge xmin AND xs[n-1,*] le xmax)]) ymax=ymax*1.1 endif npanels=!p.multi[1]*!p.multi[2] if npanels le 1 then mpauto=0 if n_elements(mpauto) eq 0 then mpauto=0 if mpauto eq 0 then plot,[1],[1],xrange=[xmin,xmax],xstyle=1,yrange=[ymin,ymax],ystyle=1,title=t,xtitle=xt,ytitle=yt,charsize=cs,/nodata for j=0,n-1 do begin if j lt n_elements(ls) then lstyle=ls[j] else begin if soro eq 0 then lstyle=0 else lstyle=j MOD 6 endelse if j lt n_elements(ps) then usep=ps[j] else usep=0 if j lt n_elements(clr) then begin if strpos(clr[j],' ') ne -1 then begin useclr=get_color(strparse(clr[j],1),strparse(clr[j],2),strparse(clr[j],3)) endif else useclr=clr[j]+0. if clr[j] eq '' then useclr=!p.color endif else useclr=!p.color if mpauto eq 1 then plot,[1],[1],xrange=[xmin,xmax],xstyle=1,yrange=[ymin,ymax],ystyle=1,title=t,xtitle=xt,ytitle=ty,charsize=cs,/nodata if soro eq 0 then begin oplot,xs[j,where(xs[j,*] ne -1)],ay[j]+ys[j,where(xs[j,*] ne -1)],psym=usep,linestyle=lstyle,color=useclr if j lt nlbl then xyouts,xmax+((xmax+0.0)-(xmin+0.0))*.005,ay[j],lbl[j],charsize=cs,alignment=0.0,/data endif else begin oplot,xs[j,where(xs[j,*] ne -1)],ys[j,where(xs[j,*] ne -1)],psym=usep,linestyle=lstyle,color=useclr if j lt nlbl then xyouts,xmax+((xmax+0.0)-(xmin+0.0))*.005,ymax-((ymax+0.0)-(ymin+0.0))/n*j,lbl[j],charsize=cs,alignment=0.0,/data endelse endfor end pro gpsexport,fname,printer=prt,color=clr,multiplot=mpt,xsize=xsz,ysize=ysz,landscape=lnd set_plot,'x' getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpscriptvars.dat' if n_elements(xsz) eq 0 then xsz=7 if n_elements(ysz) eq 0 then ysz=5 if n_elements(prt) ne 0 then fname='idl.ps' else prt=0 if n_elements(lnd) eq 0 then lnd=0 pdf=strpos(strlowcase(fname),'.pdf') if pdf ne -1 then fname=strmid(fname,0,pdf) if strpos(strlowcase(fname),'.eps') ne -1 then enc=1 else enc=0 if strpos(strlowcase(fname),'.fit') ne -1 then begin if n_elements(xmin) eq 0 then xmin=min(xs) if n_elements(xmax) eq 0 then xmax=max(xs) yfits=ys[0,where(xs[0,*] ge xmin AND xs[0,*] le xmax)] yfits=fltarr(n_elements(yfits)) yfits[*]=ys[0,where(xs[0,*] ge xmin AND xs[0,*] le xmax)] fits_write,fname,yfits fits_read,fname,yfits,header h2=strarr(n_elements(header)+3) h2[0:n_elements(header)-2]=header[0:n_elements(header)-2] h2[n_elements(header)-1]='CRVAL1 = '+string(xmin) h2[n_elements(header)]='CDELT1 = '+string(xs[0,1]-xs[0,0]) h2[n_elements(header)+1]='CD1_1 = '+string(xs[0,1]-xs[0,0]) h2[n_elements(header)+2]=header[n_elements(header)-1] fits_write,fname,yfits,h2 return endif if strpos(strlowcase(fname),'.dat') ne -1 OR strpos(strlowcase(fname),'.txt') ne -1 then begin if n_elements(xmin) eq 0 then xmin=min(xs) if n_elements(xmax) eq 0 then xmax=max(xs) asc=xs[0,where(xs[0,*] ge xmin AND xs[0,*] le xmax)] asc=fltarr(2,n_elements(asc)) asc[0,*]=xs[0,where(xs[0,*] ge xmin AND xs[0,*] le xmax)] asc[1,*]=ys[0,where(xs[0,*] ge xmin AND xs[0,*] le xmax)] openw,1,fname printf,1,asc close,1 return endif doexport=1 if n_elements(clr) eq 0 then clr=0 if n_elements(mpt) ne 0 then begin if !p.multi[0] ne 0 then doexport=-1 endif if doexport eq 1 then begin if clr eq 0 then jp=tvrd() else jp=tvrd(true=1) if strpos(strlowcase(fname),'.jp') ne -1 then begin if clr eq 0 then write_jpeg,fname,jp else write_jpeg,fname,jp,true=1 return endif if clr eq 1 then begin jpblk=where(jp[0,*,*] eq 0 and jp[1,*,*] eq 0 and jp[2,*,*] eq 0) jpwht=where(jp[0,*,*] eq 255 and jp[1,*,*] eq 255 and jp[2,*,*] eq 255) if jpwht[0] eq -1 then jpwht=where(jp[0,*,*] ge 248 and jp[1,*,*] ge 248 and jp[2,*,*] ge 248) jp[jpblk*3]=255 jp[jpblk*3+1]=255 jp[jpblk*3+2]=255 if jpwht[0] ne -1 then jp[jpwht*3]=0 if jpwht[0] ne -1 then jp[jpwht*3+1]=0 if jpwht[0] ne -1 then jp[jpwht*3+2]=0 endif else begin jpblk=where(jp eq 0) jpwht=where(jp eq 255) if jpwht[0] eq -1 then jpwht=where(jp ge 248) jp[jpblk]=255 if jpwht[0] ne -1 then jp[jpwht]=0 endelse set_plot,'ps' device,filename=fname,xs=xsz,ys=ysz,color=clr,encapsulated=enc,landscape=lnd,/inches if clr eq 0 then tv,jp else tv,jp,true=1 device,/close set_plot,'x' if prt eq 1 then begin spawn,'lpr idl.ps' spawn,'rm idl.ps' endif if pdf ne -1 then begin p2pcom='ps2pdf '+fname+' '+fname+'.pdf' spawn,p2pcom spawn,'rm '+fname endif endif end pro gpssmooth,boxcar=bx,binomial=bn,npts=npts,iter=ni getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpscriptvars.dat' if n_elements(npts) eq 0 then npts=5 if n_elements(ni) eq 0 then ni=1 smtype=0 if n_elements(bn) ne 0 then smtype=1 save, /variables, filename=varsdir+'/gatorplotvars.dat' smthar=[1,smtype,npts,ni] smoothplot,smthar,xs,ys save, /variables, filename=varsdir+'/gpscriptvars.dat' end pro gpsmath,flist1,factor1=fac1,const1=con1,oper=op,files2=flist2,factor2=fac2,const2=con2,out=outf getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpscriptvars.dat' if n_elements(fac1) eq 0 then fac1=fltarr(n_elements(flist1))+1 mmxs=fltarr(n_elements(xs[0,*])) mmxs[*]=xs[0,*] mmys=fltarr(n_elements(xs[0,*])) for j=0,n_elements(flist1)-1 do begin mmys=mmys+ys[flist1[j],*]*fac1[j] endfor if n_elements(con1) ne 0 then mmys=mmys+con1 if n_elements(op) ne 0 then begin if n_elements(fac2) eq 0 then fac2=fltarr(n_elements(flist2))+1 mmys2=fltarr(n_elements(xs[0,*])) for j=0,n_elements(flist2)-1 do begin mmys2=mmys2+ys[flist2[j],*]*fac2[j] endfor if n_elements(con2) ne 0 then mmys2=mmys2+con2 if op eq '+' then mmys=mmys+mmys2 if op eq '-' then mmys=mmys-mmys2 if op eq '*' then mmys=mmys*mmys2 if op eq '/' then mmys=mmys/mmys2 endif if strpos(strlowcase(outf),'.fit') ne -1 then begin fits_write,outf,mmys fits_read,outf,mmys,header h2=strarr(n_elements(header)+3) h2[0:n_elements(header)-2]=header[0:n_elements(header)-2] h2[n_elements(header)-1]='CRVAL1 = '+string(mmxs[0]) h2[n_elements(header)]='CDELT1 = '+string(mmxs[1]-mmxs[0]) h2[n_elements(header)+1]='CD1_1 = '+string(mmxs[1]-mmxs[0]) h2[n_elements(header)+2]=header[n_elements(header)-1] fits_write,outf,mmys,h2 endif else begin savexy=fltarr(2,n_elements(mmxs)) savexy[0,*]=mmxs savexy[1,*]=mmys openw,1,outf printf,1,savexy close,1 endelse end pro gpsintegrate,intgxc1,intgxc2,intgyc1,intgyc2,out=outf getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpscriptvars.dat' if n_elements(intgyc1) eq 0 then intgyc1=0 if n_elements(intgyc2) eq 0 then intgyc2=0 if n_elements(outf) eq 0 then outf='gpsintegrate.dat' intgslp=(intgyc2-intgyc1)/(intgxc2-intgxc1) intgyint=intgyc1-(intgslp*intgxc1) if file_test(outf) eq 0 then begin openw,1,outf printf,1,' Integ. (flux) Center Continuum Eq.W. File' endif else openw,1,outf,/append for j=0,n-1 do begin firstx=where(abs(xs[j,*]-intgxc1) eq min(abs(xs[j,*]-intgxc1))) lastx=where(abs(xs[j,*]-intgxc2) eq min(abs(xs[j,*]-intgxc2))) firstx=firstx[0] lastx=lastx[0] xstep=xs[j,firstx+1]-xs[j,firstx] intgfun=xs[j,firstx:lastx]*intgslp+intgyint intgres=total(ys[j,firstx:lastx]-intgfun)*xstep intgcon=avg(intgfun) intgeqw=intgres/intgcon intgcen=(xs[j,firstx]+xs[j,lastx])*.5 print,'File: ',files[j] print,'Integration (flux):',intgres print,'Center: ',intgcen print,'Avg f (contin): ',intgcon print,'EqW: ',intgeqw if strlen(files[j]) gt 20 then sfile='..'+strmid(files[j],strlen(files[j])-20,20) else sfile=files[j] printf,1,intgres,intgcen,intgcon,intgeqw,' '+sfile endfor close,1 end function gpsintegrate,intgxc1,intgxc2,intgyc1,intgyc2,out=outf getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpscriptvars.dat' if n_elements(intgyc1) eq 0 then intgyc1=0 if n_elements(intgyc2) eq 0 then intgyc2=0 if n_elements(outf) eq 0 then outf='gpsintegrate.dat' intgslp=(intgyc2-intgyc1)/(intgxc2-intgxc1) intgyint=intgyc1-(intgslp*intgxc1) if file_test(outf) eq 0 then begin openw,1,outf printf,1,' Integ. (flux) Center Continuum Eq.W. File' endif else openw,1,outf,/append rintg=strarr(j) for j=0,n-1 do begin firstx=where(abs(xs[j,*]-intgxc1) eq min(abs(xs[j,*]-intgxc1))) lastx=where(abs(xs[j,*]-intgxc2) eq min(abs(xs[j,*]-intgxc2))) firstx=firstx[0] lastx=lastx[0] xstep=xs[j,firstx+1]-xs[j,firstx] intgfun=xs[j,firstx:lastx]*intgslp+intgyint intgres=total(ys[j,firstx:lastx]-intgfun)*xstep intgcon=avg(intgfun) intgeqw=intgres/intgcon intgcen=(xs[j,firstx]+xs[j,lastx])*.5 print,'File: ',files[j] print,'Integration (flux):',intgres print,'Center: ',intgcen print,'Avg f (contin): ',intgcon print,'EqW: ',intgeqw if strlen(files[j]) gt 20 then sfile='..'+strmid(files[j],strlen(files[j])-20,20) else sfile=files[j] printf,1,intgres,intgcen,intgcon,intgeqw,' '+sfile rintg[j]=string(intgres)+string(intgcen)+String(intgeqw)+' '+sfile endfor close,1 return,rintg end pro gpsfwhm,fwxc1,fwxc2,xpeak=fwxcp,ypeak=fwycp,out=outf getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpscriptvars.dat' save, /variables, filename=varsdir+'/gatorplotvars.dat' smoothplot,[1,0,5,1],xs,ys if n_elements(fwxcp) eq 0 then fwxcp=0 if n_elements(fwycp) eq 0 then fwycp=0 if n_elements(outf) eq 0 then outf='gpsfwhm.dat' if file_test(outf) eq 0 then begin openw,1,outf printf,1,' FWHM FWHM (km/s) Center File' endif else openw,1,outf,/append for j=0,n-1 do begin xpos1=where(abs(fwxc1-xs[j,*]) eq min(abs(fwxc1-xs[j,*]))) xpos2=where(abs(fwxc2-xs[j,*]) eq min(abs(fwxc2-xs[j,*]))) xpos1=xpos1[0] xpos2=xpos2[0] if fwxcp eq 0 OR j gt 0 then begin fwycp=max(ys[j,xpos1:xpos2]) fwxcp=where(ys[j,*] eq fwycp) fwxcp=xs[j,fwxcp[0]] endif xposp=where(abs(fwxcp-xs[j,*]) eq min(abs(fwxcp-xs[j,*]))) xposp=xposp[0] con1=avg(ys[j,xpos1-2:xpos1+2]) con2=avg(ys[j,xpos2-2:xpos2+2]) hm1=(fwycp+con1)/2. hm2=(fwycp+con2)/2. fwpos1=where(ys[j,xpos1:xposp] ge hm1)+xpos1 while fwpos1[3]-fwpos1[0] gt 5 do begin fwpos1=fwpos1[1:n_elements(fwpos1)-1] endwhile fwpos2=where(ys[j,xposp:xpos2] le hm2)+xposp while fwpos2[3]-fwpos2[0] gt 5 do begin fwpos2=fwpos2[1:n_elements(fwpos2)-1] endwhile if hm1 lt con1 then begin fwpos1=where(ys[j,xpos1:xposp] le hm1)+xpos1 while fwpos1[3]-fwpos1[0] gt 5 do begin fwpos1=fwpos1[1:n_elements(fwpos1)-1] endwhile fwpos2=where(ys[j,xposp:xpos2] ge hm2)+xposp while fwpos2[3]-fwpos2[0] gt 5 do begin fwpos2=fwpos2[1:n_elements(fwpos2)-1] endwhile endif fwhm=xs[j,fwpos2[0]]-xs[j,fwpos1[0]] vfwhm=fwhm*3.e+5/fwxcp print,'File: ',files[j] print,'FWHM: '+string(fwhm) print,'FWHM (km/s): '+string(vfwhm) print,'Center: '+string(fwxcp) if strlen(files[j]) gt 20 then sfile='..'+strmid(files[j],strlen(files[j])-20,20) else sfile=files[j] printf,1,fwhm,vfwhm,fwxcp,' '+sfile endfor close,1 end function gpsfwhm,fwxc1,fwxc2,xpeak=fwxcp,ypeak=fwycp,out=outf getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpscriptvars.dat' save, /variables, filename=varsdir+'/gatorplotvars.dat' smoothplot,[1,0,5,1],xs,ys if n_elements(fwxcp) eq 0 then fwxcp=0 if n_elements(fwycp) eq 0 then fwycp=0 if n_elements(outf) eq 0 then outf='gpsfwhm.dat' if file_test(outf) eq 0 then begin openw,1,outf printf,1,' FWHM FWHM (km/s) Center File' endif else openw,1,outf,/append rfwhm=strarr(n) for j=0,n-1 do begin xpos1=where(abs(fwxc1-xs[j,*]) eq min(abs(fwxc1-xs[j,*]))) xpos2=where(abs(fwxc2-xs[j,*]) eq min(abs(fwxc2-xs[j,*]))) xpos1=xpos1[0] xpos2=xpos2[0] if fwxcp eq 0 OR j gt 0 then begin fwycp=max(ys[j,xpos1:xpos2]) fwxcp=where(ys[j,*] eq fwycp) fwxcp=xs[j,fwxcp[0]] endif xposp=where(abs(fwxcp-xs[j,*]) eq min(abs(fwxcp-xs[j,*]))) xposp=xposp[0] con1=avg(ys[j,xpos1-2:xpos1+2]) con2=avg(ys[j,xpos2-2:xpos2+2]) hm1=(fwycp+con1)/2. hm2=(fwycp+con2)/2. fwpos1=where(ys[j,xpos1:xposp] ge hm1)+xpos1 while n_elements(fwpos1) lt 4 do fwpos1=[fwpos1,fwpos1[n_elements(fwpos1)-1]] while fwpos1[3]-fwpos1[0] gt 5 do begin fwpos1=fwpos1[1:n_elements(fwpos1)-1] endwhile fwpos2=where(ys[j,xposp:xpos2] le hm2)+xposp while fwpos2[3]-fwpos2[0] gt 5 do begin fwpos2=fwpos2[1:n_elements(fwpos2)-1] endwhile if hm1 lt con1 then begin fwpos1=where(ys[j,xpos1:xposp] le hm1)+xpos1 while fwpos1[3]-fwpos1[0] gt 5 do begin fwpos1=fwpos1[1:n_elements(fwpos1)-1] endwhile fwpos2=where(ys[j,xposp:xpos2] ge hm2)+xposp while fwpos2[3]-fwpos2[0] gt 5 do begin fwpos2=fwpos2[1:n_elements(fwpos2)-1] endwhile endif fwhm=xs[j,fwpos2[0]]-xs[j,fwpos1[0]] vfwhm=fwhm*3.e+5/fwxcp print,'File: ',files[j] print,'FWHM: '+string(fwhm) print,'FWHM (km/s): '+string(vfwhm) print,'Center: '+string(fwxcp) if strlen(files[j]) gt 20 then sfile='..'+strmid(files[j],strlen(files[j])-20,20) else sfile=files[j] printf,1,fwhm,vfwhm,fwxcp,' '+sfile rfwhm[j]=string(fwhm)+string(vfwhm)+string(fwxcp)+' '+sfile endfor close,1 return,rfwhm end pro gpslinfit,range=gpfxrng,poisson=gpferrs,out=outf,plotps=psfile,plotxrange=pxrng getgpconfig,cfgexists,gpcfg varsdir='$HOME' if cfgexists eq 1 then begin varsdir=strmid(gpcfg[where(strmid(gpcfg,0,4) eq 'VARS')],10,150) varsdir=strcompress(varsdir[0],/remove_all) endif restore, varsdir+'/gpscriptvars.dat' if n_elements(outf) eq 0 then outf='linfit.gp' if n_elements(gpferrs) eq 0 then gpferrs=0 if n_elements(gpfxrng) eq 0 then gpfxrng='' if n_elements(psfile) ne 0 then begin if n_elements(pxrng) eq 0 then pxrng=[min(xs),max(xs)] set_plot,'ps' device,filename=psfile gpsplot,xmin=pxrng[0],xmax=pxrng[1],color=intarr(n) endif ay=fltarr(n) ay[0]=0 for j=1,n-1 do begin ayz=max(ys[j-1,*]) ay[j]=ay[j-1]+floor(10.^ceil(alog10(1./ayz))*ayz+.99)/10.^ceil(alog10(1./ayz)) endfor for l=0,n-1 do begin if strcompress(gpfxrng[0],/remove_all) eq '' then xfit=findgen(n_elements(xs[l