| Please, read the readme.txt file and tell any problems and bugs to me: | Jaap Vente | Cinvestav-IPN Unidad Merida | Departemento de Fisica Aplicada | Carretera Ant. a Progreso km 6 | Apartado Postal #73 Cordemex | Merida, Yucatan, 97310 | Mexico | Fax: (..) 52 - 99 - 812917 | Tel: (..) 52 - 99 - 812960 ext 246 | e-mail: jaap@jade.cieamer.conacyt.mx MACRO LoadData () Silent 1 DefaultFont "Helvetica" ToforCw() draw_it() DisplayModifier() ENDMACRO proc ToforCw(TorC) variable TorC=0 Prompt TorC, "What kind of radiation did you use?", Popup,("X-ray Cu ; Neutron Constant Wavelength; Neutron Time of Flight; X-ray other lambda") If (TorC==1) Xraycu() else If (TorC==2) NeutronCW() else If (TorC==3) NeutronTOF() Else If (TorC==4) XrayVar() Endif Endif Endif Endif End proc Xraycu(check) variable check prompt check, "Do you want me to check for excluded regions?",popup, ("No;Yes") Variable/G golflen=1.542,checkex=check,TOF=0 Do_a_bit_of_reading() endmacro proc NeutronCW(wave,check) variable wave=0,check prompt wave, "Give wavelength (D1b 2.522, D2b 1.594):" prompt check, "Do you want me to check for excluded regions?",popup, ("No;Yes") Variable/G golflen=wave,checkex=check,TOF=0 Do_a_bit_of_reading() Endmacro proc NeutronTOF(difal,difcl,zerol,check) variable difal,difcl,zerol,check=0 prompt difal, "Please give DIFA:" prompt difcl, "Please give DIFC:" prompt zerol, "Please give ZERO:" prompt check, "Do you want me to check for excluded regions?",popup, ("No;Yes") Variable/G difa=difal, difc=difcl, zero=zerol,TOF=1,checkex=check Do_a_bit_of_reading() Endmacro proc Xrayvar(wave,check) variable wave=0,check prompt wave, "Give wavelength:" prompt check, "Do you want me to check for excluded regions?",popup, ("No;Yes") Variable/G golflen=wave,checkex=check,TOF=0 Do_a_bit_of_reading() Endmacro PROC DO_A_BIT_OF_READING() variable/G num_of_ref,fases,mino,maxo,maxd,mind,Ishift,ishifto, gap variable/G numofpoints ,i2,ii,exclude=0,Nexclude=0,minl, exbeg, exend, excludver=0, variable/G HighTick1=0, HighTick2=0, HighTick3=0, HighTick4=0, Runbefore=0, x_axismin, x_axismax, x_axisminplot, x_axismaxplot string/g LabelFsize="12",Fonttype="00" variable/g AxisFsize=10,Fonttypev=0 make/n=5 fontcheck=0 Make/n=2 zeroline,zeroheight Make/n=20 excludehor Doalert 0 "Please provide the file created with Export ." loadwave/q/g/n=tmp duplicate tmp0 x_axis,stepwave IF (TOF ==0) x_axis=tmp0 ELSE x_axis=tmp0 ENDIF duplicate tmp1 iobs duplicate tmp2 icalc,idif idif=iobs-icalc wavestats/q x_axis duplicate tmp3 icod,dspace,pos_tickmark, HighTickMark1, HighTickMark2, HighTickMark3, HighTickMark4 icod=tmp3 dspace=tmp4 killwaves tmp0,tmp1,tmp2,tmp3,tmp4 | Calculate d-spacing out of TOF values in millisecs | Be aware Export is in musecs and Hstdmp is in millisecs If (TOF == 1) duplicate x_axis TOF_mill x_axis=(-difc+sqrt((difc*difc)-(4*difa*(zero-(tof_mill*1000)))))/(2*difa) Endif | Everything is read in now and all the waves have been created | setting the height of the tickmarks at a low value so it won't be displayed HighTickMark1=-10000000 HighTickMark2=-10000000 HighTickMark3=-10000000 HighTickMark4=-10000000 |Calculating the number of phases, reflections and which reflection belongs to which phase icod=floor(icod/1000) wavestats/Q icod fases=V_max num_of_ref=V_npnts | Checking whether the number of phases is between one and four! IF (fases>4) ABORT "You have been working with over 4 phases, DUMBO; Macro aborted." ENDIF IF (fases==0) ABORT "No phases present, Macro aborted." ENDIF | calculating the position of the tickmark in terms of the x-axis. If (TOF==0) pos_tickmark=(360/pi)*(asin(golflen/(2*dspace))) else pos_tickmark=dspace Endif END | Now all parameters are done, and below the values of some more variables are determined | and the actual building of the graph is done. proc DRAW_IT() |if this is the first time the graph is build some default values are required. | Otherwise manully given values from Diffmodifier will be used String labbottom,lableft If (Wintype("graph0")==1) Print "Closing graph and displaying the whole lot again." Dowindow/K graph0 Endif If (runbefore==0) | Sorting out the exclude regions wavestats/q x_axis x_axismin=v_min x_axismax=v_max zeroline={v_min,v_max} numofpoints=V_npnts If (checkex==2) Check_excluded_region() endif If (exclude==0) Print "No regions were excluded" minl=mind-gap Else Print Nexclude," excluded regions were processed." Endif | Sorting out some values for the scaling of the y-axis, getting maximum and minimum intensities | for observed, calculated and differences curves. |gap is the space available for the tickmarks |lshift is the vertical position of the line where idif=0 |which can be rather different from where Iobs=0 print "There are " ,num2str(fases)," fases and ",num2str(num_of_ref)," reflections present." print "Determining positions of the tickmarks" wavestats/Q iobs maxo=V_max mino=V_min Wavestats/Q icalc IF (V_max>maxo) maxo=V_max ENDIF If (V_min < mino) Mino=V_min Endif Wavestats/Q idif maxd=V_max mind=V_min gap=(fases*.8/16)*((maxo-mino)+(maxd-mind)) Ishift=floor(mino-maxd-gap) zeroheight=Ishift Idif+=Ishift |moving the difference profile to the same height of the zeroline ishifto=ishift |Below the distribution of the tickmarks in the gap is calculated |Setting scale for the x axis (2-theta or d-spacing) x_axisminplot= x_axismin - 0.025*(x_axismax - x_axismin) IF (x_axismin < 0) x_axisminplot = 0 ENDIF x_axismaxplot=x_axismax + 0.025*(x_axismax - x_axismin) ELSE zeroheight=Ishift idif=idif-ishifto+ishift ishifto=ishift ENDIF I2=0 IF (FASES==4) |The case of four phases | calculating the height of the tickmarks If (runbefore==0) HighTick1=floor(mino-0.8*gap) HighTick2=floor(mino-.6*gap) HighTick3=floor(mino-.4*gap) HighTick4=floor(mino-.2*gap) Endif | Sorting out which tickmarks belong to which phase and give it the | appropriate position ITERATE (num_of_ref) IF ((pos_tickmark[i2]> x_axismin)%&(pos_tickmark[i2] < x_axismax)) IF (icod[i2]==1) HighTickMark1[i2]=HighTick1 ELSE IF (icod[i2]==2) HighTickMark2[i2]=HighTick2 ELSE If (Icod[i2]==3) HighTickMark3[i2]=HighTick3 Else HighTickMark4[i2]=HighTick4 Endif ENDIF ENDIF ENDIF I2+=1 LOOP ELSE IF (FASES==3) | The case of three phases present see above for more comment If (runbefore==0) HighTick1=floor(mino-0.75*gap) HighTick2=floor(mino-.5*gap) HighTick3=floor(mino-.25*gap) Endif ITERATE (num_of_ref) IF ((pos_tickmark[i2]>x_axismin)%&(pos_tickmark[i2] < x_axismax)) IF (icod[i2]==1) HighTickMark1[i2]=HighTick1 ELSE IF (icod[i2]==2) HighTickMark2[i2]=HighTick2 ELSE HighTickMark3[i2]=HighTick3 ENDIF ENDIF ENDIF I2+=1 LOOP ELSE IF (FASES==2) | The case of two phases present see above for more comment If (runbefore==0) HighTick1=floor(mino-.66*gap) HighTick2=floor(mino-.33*gap) endif ITERATE (num_of_ref) IF ((pos_tickmark[i2]>x_axismin)%&(pos_tickmark[i2] < x_axismax)) IF (icod[i2]==1) HighTickMark1[i2]=HighTick1 ELSE HighTickMark2[i2]=HighTick2 ENDIF ENDIF I2+=1 LOOP ELSE | The case of one phase present see above for more comment If (runbefore==0) HighTick1=floor(mino-.5*gap) endif ITERATE (num_of_ref) IF ((pos_tickmark[i2]>x_axismin)%&(pos_tickmark[i2] < x_axismax)) HighTickMark1[i2]=HighTick1 ENDIF I2+=1 LOOP ENDIF ENDIF ENDIF runbefore=1 wavestats/q idif minl=v_min Ii=0 Do If (excludehor [ii] > 0) icalc[excludehor[ii] ]=excludver icalc[excludehor[ii]+1]=excludver idif[excludehor[ii]]=ishift idif[excludehor[ii]+1]=ishift Endif ii+=1 While(ii<19) |Prepare the label of the x-axis, depending on whether is TOF or CW If (TOF==0) labbottom="\f"+Fonttype+"\Z"+LabelFsize+"2\F'Symbol'q\F]0 / " lableft="\f"+Fonttype+"\Z"+LabelFsize+ "Intensity / \u\Z"+LabelFsize+" counts" Else labbottom="\f"+Fonttype+"\Z"+LabelFsize+"d - spacing / " lableft="\f"+Fonttype+"\Z"+LabelFsize+ "Intensity / \u\Z " Endif |The actual display is being build here! Display Iobs,Icalc, idif vs x_axis;delayupdate Append HighTickMark1,HighTickMark2,HighTickMark3,HighTickMark4 vs pos_tickmark; delayupdate append zeroheight vs zeroline;delayupdate Modify mode(iobs)=2,lsize(iobs)=1.5;DelayUpdate Modify mode(icalc)=0,lsize(icalc)=0.3;DelayUpdate Modify mode(HighTickMark1)=3, marker(HighTickMark1)=10, msize(HighTickMark1)=3, mrkThick(HighTickMark1)=0.3 ;DelayUpdate Modify mode(HighTickMark2)=3, marker(HighTickMark2)=10, msize(HighTickMark2)=3, mrkThick(HighTickMark2)=0.3 ;DelayUpdate Modify mode(HighTickMark3)=3, marker(HighTickMark3)=10, msize(HighTickMark3)=3, mrkThick(HighTickMark3)=0.3 ;DelayUpdate Modify mode(HighTickMark4)=3, marker(HighTickMark4)=10, msize(HighTickMark4)=3, mrkThick(HighTickMark4)=0.3 ;DelayUpdate Modify mode(idif)=0,lsize(idif)=0.3;DelayUpdate Modify mode(zeroheight)=0,lsize(zeroheight)=0.3;DelayUpdate setaxis bottom x_axisminplot,x_axismaxplot; delayupdate setaxis left minl,maxo;delayupdate Label bottom labbottom;DelayUpdate Label left lableft; DelayUpdate Modify fSize=AxisFsize; DelayUpdate modify fstyle=fonttypev;DelayUpdate modify mirror=2;delayupdate modify axoffset=1;modify lblmargin=1;DelayUpdate modify rgb=(0,0,0) END |Searching for excluded regions proc Check_excluded_region() variable,nagging=0 print "Parts of the diffraction pattern with more than two consecutive zero calculated intensities" print "will be treated as an excluded region. The user will be requested to confirm this." ii=0 Do If (Icalc[ii]==0) Exbeg=ii Do Exend=ii ii+=1 While (icalc[ii] ==0) If (Exend-Exbeg > 2) If (nagging==3) Doexclude() Else If (tof ==0) print "Excluded region found between : ", x_axis[exbeg] ," and " , x_axis[exend]," 2-theta." Else print "Excluded region found between : ", x_axis[exbeg] ," and " , x_axis[exend]," ." Endif Doalert 2 "Do you want to exclude the current region? (Yes is Yes; No is No ; Cancel is DO ALL AND DON'T NAG ME AGAIN)" if (V_flag==1) Doexclude() Else if (V_flag==3) nagging=3 Doexclude() Else Print "The region is NOT excluded." Print "Continuing ........" Endif Endif Endif Endif Endif ii+=1 While(ii < numofpoints) If (exclude==0) Idif-=mino minl=mind-gap-mino mino=0 Ishift=floor(-maxd-gap) zeroheight=Ishift ishifto=ishift exclude=1 Endif endmacro |The regions are here nicely excluded Proc Doexclude() If (tof==0) print "The region between between : ", x_axis[exbeg] ," and " , x_axis[exend]," 2-theta is excluded." Else print "The region between between : ", x_axis[exbeg] ," and " , x_axis[exend]," is excluded." Endif Print "Continuing ........" DeletePoints exbeg+1,exend-exbeg-1,icalc,iobs,x_axis,idif Excludehor[Nexclude]=exbeg Nexclude+=1 Ii=ii+2-(exend-exbeg-1) endmacro Macro Publication() silent 1 layout graph0/F=0 ModifyLayout left(graph0)=29, top(graph0)=29, width(graph0)=540, height(graph0)=360 END Window DisplayModifier() : Panel PauseUpdate; Silent 1 | building window... NewPanel /W=(400,40,630,440) | is 230 by 400 ModifyPanel cbRGB=(32769,65535,32768) SetDrawLayer UserBack SetDrawEnv rounding= 20 DrawRRect 9,25,221,189 SetDrawEnv fname= "Helvetica",fstyle= 1,textrgb= (0,0,65535),textxjust= 1 DrawText 115,20,"Default settings for font(sizes)" SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1 DrawText 130,39,"Default font for graphs:" PopupMenu popupFont,pos={133,30},size={149,19}, title="", proc=changedeffont PopupMenu popupFont,mode=1,value= "Helvetica;Times;Palatino" SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1 DrawText 130,59,"Default label size:" PopupMenu popupLsize,pos={133,50},size={149,19}, title="", proc=changeLabelsize PopupMenu popupLsize,mode=3,value= "9;10;12;14;16;18;24;30" SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1 DrawText 130,79,"Default axis size:" PopupMenu popupasize,pos={133,70},size={149,19}, title="", proc=changeaxissize PopupMenu popupasize,mode=2,value="9;10;12;14;16;18;24;30" SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1,fstyle=01 DrawText 130,99,"Bold type face:" Checkbox checkbold, pos={133,92},size={15,15}, noproc,title="", value=0 SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1,fstyle=02 DrawText 130,119,"Italic type face:" Checkbox checkital, pos={133,112},size={15,15}, noproc,title="", value=0 SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1,fstyle=04 DrawText 130,139,"Underlined:" Checkbox checkundl, pos={133,132},size={15,15}, noproc,title="", value=0 SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1,fstyle=08 DrawText 130,159,"Outline type face:" Checkbox checkoutl, pos={133,152},size={15,15}, noproc,title="", value=0 SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1,fstyle=16 DrawText 130,179,"Shadow type face:" Checkbox checkshad, pos={133,172},size={15,15}, noproc,title="", value=0 SetDrawEnv fname= "Helvetica",fstyle= 1,textrgb= (0,0,65535),textxjust= 1 DrawText 115,206,"Set values for height adjustment" SetDrawEnv rounding= 20 DrawRRect 9,210,221,340 SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1 DrawText 130,224,"Height of zeroline:" SetVariable setvar1,pos={133,217},size={50,13},title=" " SetVariable setvar1,fSize=10,limits={-INF,mino,0},value=ishift SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1 DrawText 130,244,"Height of exclusion zones:" SetVariable setvar2,pos={133,237},size={50,13},title=" " SetVariable setvar2,fSize=10,limits={-INF,maxo,0},value=excludver SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1 DrawText 130,264,"Height of tickmark 1:" SetVariable setvar3,pos={133,257},size={50,13},title=" " SetVariable setvar3,fSize=10,limits={-INF,mino,0},value=HighTick1 SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1 DrawText 130,284,"Height of tickmark 2:" SetVariable setvar4,pos={133,277},size={50,13},title=" " SetVariable setvar4,fSize=10,limits={-INF,mino,0}, value=HighTick2 SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1 DrawText 130,304,"Height of tickmark 3:" SetVariable setvar5,pos={133,297},size={50,13},title=" " SetVariable setvar5,fSize=10,limits={-INF,mino,0},value=HighTick3 SetDrawEnv fname= "Geneva",fsize= 9,textxjust= 2,textyjust= 1 DrawText 130,324,"Height of tickmark 4:" SetVariable setvar6,pos={133,317},size={50,13},title=" " SetVariable setvar6,fSize=10,limits={-INF,mino,0},value=HighTick4 | Button Execute, pos={51,357}, size={114,25}, proc=ApplyChanges, title="Execute" EndMacro Function changedeffont(popupFont,popNum,popStr) : PopupMenuControl String popupFont Variable popNum | which item number currently selected (1-based) String popStr | contents of current popup item as string if (popnum==1) Defaultfont "Helvetica";Delayupdate else if (popnum==2) Defaultfont "Times";Delayupdate else if (popnum==3) Defaultfont "Palatino";Delayupdate endif endif endif End Function changeLabelsize(popupLsize,popNum,popStr) : PopupMenuControl String popupLsize Variable popNum | which item number currently selected (1-based) String popStr | contents of current popup item as string string labelfsizel string/g labelfsize if (popnum==1) LabelFsizel="9" else if (popnum==2) LabelFsizel="10" else if (popnum==3) LabelFsizel="12" else if (popnum==4) LabelFsizel="14" else if (popnum==5) LabelFsizel="16" else if (popnum==6) LabelFsizel="18" else if (popnum==7) LabelFsizel="24" else if (popnum==8) LabelFsizel="30" endif endif endif endif endif endif endif endif LabelFsize=LabelFsizel End Function changeaxissize(changeaxissize,popNum,popStr) : PopupMenuControl String changeaxissize Variable popNum | which item number currently selected (1-based) String popStr | contents of current popup item as string variable axisfsizel variable/g axisfsize if (popnum==1) AxisFsizel=9 else if (popnum==2) AxisFsizel=10 else if (popnum==3) AxisFsizel=12 else if (popnum==4) AxisFsizel=14 else if (popnum==5) AxisFsizel=16 else if (popnum==6) AxisFsizel=18 else if (popnum==7) AxisFsizel=24 else if (popnum==8) AxisFsizel=30 endif endif endif endif endif endif endif endif AxisFsize=AxisFsizel End Proc ApplyChanges(cntrlname) : ButtonControl string cntrlname Controlinfo/w=DisplayModifier checkbold; fontcheck[0]=V_value Controlinfo/w=DisplayModifier checkital; fontcheck[1]=V_value Controlinfo/w=DisplayModifier checkundl; fontcheck[2]=V_value Controlinfo/w=DisplayModifier checkoutl; fontcheck[3]=V_value Controlinfo/w=DisplayModifier checkshad; fontcheck[4]=V_value fonttypev=fontcheck[0]+ 2*fontcheck[1]+ 4*fontcheck[2]+ 8*fontcheck[3] + 16*fontcheck[4] if (fonttypev < 10) fonttype="0"+num2str(fonttypev) else fonttype=num2str(fonttypev) endif Draw_it() endmacro proc TryToRestoreRefl() Doalert 0 "An error during read occurred. I will try to resolve the problem." print "No, I don't!!!!!!" Endmacro proc TryToResoreHist() variable/g Lengthofx_axis, VARIABLE i=1,lengthoftyd,j,lengthzero,lengthsfour,lengths,TofError,RemoveDigits string x_axistemp,iobstemp,icalctemp,zerotemp,onetemp duplicate tyd0 x_axis,iobs,icalc,zeronow,one Make/d/n=5 temp x_axis=tyd2;iobs=tyd3;icalc=tyd4 wavestats/Q x_axis lengthofx_axis=v_npnts do print " " j=0 toferror=0 zerotemp="tyd"+num2str(0+5*i) onetemp="tyd"+num2str(1+5*i) x_axistemp="tyd"+num2str(2+5*i) iobstemp="tyd"+num2str(3+5*i) icalctemp="tyd"+num2str(4+5*i) wavestats/Q $x_axistemp lengthoftyd=v_npnts Print "Working on dodgy region no." + num2str(i) + " with is " + num2str(lengthoftyd) + " data points long, starting at no. " + num2str(lengthofx_axis) If (lengthoftyd > 100) Print "This may take some time do not interrupt!" Endif | Checking on merging of early columns if ((zeronow[lengthofx_axis-1]+1) != $zerotemp[0]) If ((($zerotemp[0])- (floor($zerotemp[0])) > E-1)%| (($zerotemp[1])- (floor($zerotemp[1])) > E-1)) Print "First three columns are merged" TofError=3 else Print "First two columns are merged." TofError=1 Endif else If ((1000*($onetemp[0]- (floor($onetemp[0]))) > E-1)%| (1000*($onetemp[1]- (floor($onetemp[1]))) > E-1)) Print "Second and third column are merged." TofError=2 endif endif If (TofError==0) print "None of the first five columns are merged." Endif If (TofError==1) $zerotemp=lengthofx_axis+1+x onetemp="tyd"+num2str(5*i) x_axistemp="tyd"+num2str(1+5*i) iobstemp="tyd"+num2str(2+5*i) icalctemp="tyd"+num2str(3+5*i) endif If (TofError>1) If (Toferror == 2) x_axistemp="tyd"+num2str(1+5*i) iobstemp="tyd"+num2str(2+5*i) icalctemp="tyd"+num2str(3+5*i) Else x_axistemp="tyd"+num2str(+5*i) iobstemp="tyd"+num2str(1+5*i) icalctemp="tyd"+num2str(2+5*i) Endif temp[0]=x_axis[lengthofx_axis-2]-floor(x_axis[lengthofx_axis-2]) temp[1]=x_axis[lengthofx_axis-1]-floor(x_axis[lengthofx_axis-1]) temp[2]=$x_axistemp[0]-floor($x_axistemp[0]) temp[3]=$x_axistemp[1]-floor($x_axistemp[1]) If (temp[1] < temp[0]) temp[1]=temp[1]+1 temp[2]=temp[2]+1 temp[3]=temp[3]+1 Endif If (temp[2] < temp[1]) temp[2]=temp[2]+1 temp[3]=temp[3]+1 Endif If (temp[3] < temp[2]) temp[3]=temp[3]+1 Endif Temp[4]=abs(1-abs(2*(temp[2]-temp[1]))/((temp[3]-temp[2])+(temp[1]-temp[0]))) If (temp[4] < .5) Print "Stepsize seems OK, attempt to remove some digits." temp[0]=ceil(log(floor(x_axis[lengthofx_axis-1])+.5)) temp[1]=ceil(log(floor($x_axistemp[0])+.5)) temp[2]=log(ceil(x_axis[lengthofx_axis-1])) temp[2]=temp[2]-floor(temp[2]) If (100*temp[2]