pro changablestep st='' datapath='' plotpath='' read,datapath,prompt='请输入数据路径,例如F:data.dat' read,st,prompt='按第一列分组请输入:one,按第二列分组请输入:two ' read,step,prompt='请输入步长:' read,plotpath,prompt='请输入图片存储路径,例如F:image.ps' print,plotpath ;按第一列分组 if strcmp(st,'one') then begin READCOL,datapath,F='f,f',col1,col2 endif ;按第二列分组 if strcmp(st,'two') then begin READCOL,datapath,F='f,f',col2,col1 endif result1=min(col1) result2=max(col1) result3=result2-result1 r1=result3/step L=round(r1) if round(r1) ge r1 then begin L=round(r1)-1
endif
i=0 x=fltarr(L+1) y=fltarr(L+1) while i le L do begin step1=result1+i*step step2=result1+(i+1)*step x[i]=(step2+step1)/2.0 ave=0.0 m=0 k=0 n=n_elements(col1)-1 while k le n do begin if col1[k] ge step1 and col1[k] lt step2 then begin m=m+1 ave=ave+col2[k] endif k++ endwhile
if m eq 0 then begin y[i]=ave/(m+1) endif if m ne 0 then begin y[i]=ave/m endif i++ endwhile n1=0 i=0 while i le L do begin if y[i] ne 0.0 then begin n1++ endif i++ endwhile x1=fltarr(n1) y1=fltarr(n1) help,x1 n2=0 i=0 while i le L do begin if y[i] ne 0.0 then begin x1[n2]=x[i] y1[n2]=y[i] n2++ endif i++ endwhile
print,x1,y1 set_plot,'ps' device,file=plotpath coeff=linfit(x1,y1) yfit=coeff[0]+coeff[1]*x1 plot,x1,y1,psym=2 oplot,x1,yfit device,/close end