- Timestamp:
- Sep 30, 2010 12:01:08 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Common/Packages/LinearizedFits/LinearizedFits_v40.ipf
r746 r749 20 20 // - DID NOT prepend "A_" to the loader/unloader which is unique to this package 21 21 // 22 // SEP 2010 - absorbed the duplicate procedure file FIT_Ops. 23 // - removed "A_" prefix 24 // - need to keep A_OpenFitPanel() in case old experiments are looking for this 25 // - added the (completely unused) FITRPA procedures to this file 22 26 // 23 27 /////////////////////////////// … … 33 37 // of the FIT/RPA panel) 34 38 // 35 Proc A_OpenFitPanel()36 If(WinType(" A_FitPanel") == 0)39 Proc OpenFitPanel() 40 If(WinType("FitPanel") == 0) 37 41 //create the necessary data folder 38 42 NewDataFolder/O root:Packages … … 47 51 Variable/G root:Packages:NIST:FIT:gBack = 0 48 52 String/G root:Packages:NIST:FIT:gDataPopList = "none" 49 A_FitPanel()53 FitPanel() 50 54 else 51 55 //window already exists, just bring to front for update 52 DoWindow/F A_FitPanel56 DoWindow/F FitPanel 53 57 CheckBox check0,value=0 //deselect the checkbox to use cursors 54 58 endif 55 59 //pop the file menu 56 A_FIT_FilePopMenuProc("",1,"") 60 FIT_FilePopMenuProc("",1,"") 61 End 62 63 Proc A_OpenFitPanel() 64 OpenFitPanel() 57 65 End 58 66 59 67 //the actual window recreation macro to draw the fit panel. Globals and data folder must 60 68 // already be initialized 61 Window A_FitPanel()62 //String angst = root:Packages:NIST:gAngstStr63 String angst = "A"69 Window FitPanel() 70 String angst = root:Packages:NIST:gAngstStr 71 // String angst = "A" 64 72 PauseUpdate; Silent 1 // building window... 65 73 NewPanel /W=(461,46,735,455)/K=1 … … 74 82 PopupMenu ywave,pos={13,60},size={154,19},title="Data File" 75 83 PopupMenu ywave,help={"Select the experimental intensity values"} 76 PopupMenu ywave,mode=1,value=root:Packages:NIST:FIT:gDataPopList,proc= A_FIT_FilePopMenuProc77 Button loadButton,pos={13,92},size={130,20},proc= A_FIT_Load_Proc,title="Load and Plot File"84 PopupMenu ywave,mode=1,value=root:Packages:NIST:FIT:gDataPopList,proc=FIT_FilePopMenuProc 85 Button loadButton,pos={13,92},size={130,20},proc=FIT_Load_Proc,title="Load and Plot File" 78 86 Button loadButton,help={"After choosing a file, load it into memory and plot it with this button."} 79 Button helpButton,pos={237,28},size={25,20},proc= A_showFITHelp,title="?"87 Button helpButton,pos={237,28},size={25,20},proc=showFITHelp,title="?" 80 88 Button helpButton,help={"Show help file for linearized fitting"} 81 89 PopupMenu ymodel,pos={20,281},size={76,19},title="y-axis" 82 90 PopupMenu ymodel,help={"This popup selects how the y-axis will be linearized based on the chosen data"} 83 91 PopupMenu ymodel,mode=1,value= #"\"I;log(I);ln(I);1/I;I^a;Iq^a;I^a q^b;1/sqrt(I);ln(Iq);ln(Iq^2)\"" 84 Button GoFit,pos={60,367},size={70,20},proc= A_DispatchModel,title="Do the Fit"92 Button GoFit,pos={60,367},size={70,20},proc=DispatchModel,title="Do the Fit" 85 93 Button GoFit,help={"This button will do the specified fit using the selections in this panel"} 86 Button DoneButton,pos={180,367},size={50,20},proc= A_FITDoneButton,title="Done"94 Button DoneButton,pos={180,367},size={50,20},proc=FITDoneButton,title="Done" 87 95 Button DoneButton,help={"This button will close the panel and the associated graph"} 88 96 SetVariable lolim,pos={64,147},size={134,17},title="Lower Limit" … … 109 117 SetVariable expc,help={"This sets the exponent \"c\" for some x-axis formats. The value is ignored if the model does not use \"c\" as an adjustable exponent"} 110 118 SetVariable expc,limits={-10,10,0},value= root:Packages:NIST:FIT:gExpC 111 Button sh_all,pos={65,193},size={130,20},proc= A_ShowAllButtonProc,title="Show Full q-range"119 Button sh_all,pos={65,193},size={130,20},proc=ShowAllButtonProc,title="Show Full q-range" 112 120 Button sh_all,help={"Use this to show the entire q-range of the data rather than just the fitted range."} 113 121 114 Button FIT_PathButton,pos={10,28},size={80,20},proc= A_FIT_PickPathButtonProc,title="Pick Path"122 Button FIT_PathButton,pos={10,28},size={80,20},proc=FIT_PickPathButtonProc,title="Pick Path" 115 123 116 124 EndMacro 117 125 118 126 119 Proc A_FITDoneButton(ctrlName): ButtonControl127 Proc FITDoneButton(ctrlName): ButtonControl 120 128 String ctrlName 121 DoWindow/K A_FitWindow122 DoWindow/K A_FitPanel129 DoWindow/K FitWindow 130 DoWindow/K FitPanel 123 131 end 124 132 125 Proc A_showFITHelp(ctrlName): ButtonControl133 Proc showFITHelp(ctrlName): ButtonControl 126 134 String ctrlName 127 135 DisplayHelpTopic/Z/K=1 "Linearized Fits" … … 133 141 //Loads the selected file for fitting 134 142 //graphs the data as needed 135 Proc A_FIT_Load_Proc(ctrlName): ButtonControl143 Proc FIT_Load_Proc(ctrlName): ButtonControl 136 144 String ctrlName 137 145 … … 149 157 Endif 150 158 //get a valid file based on this partialName and catPathName 151 tempName = A_FindValidFilename(partialName)159 tempName = FindValidFilename(partialName) 152 160 153 161 //prepend path to tempName for read routine … … 157 165 158 166 //load in the data (into the root directory) 159 A_LoadOneDDataWithName(tempName,0) //let A_Rescale_Data() do the plotting167 A_LoadOneDDataWithName(tempName,0) //let Rescale_Data() do the plotting 160 168 //Print S_fileName 161 169 //Print tempName … … 171 179 172 180 //Plot, and adjust the scaling to match the axis scaling set by the popups 173 A_Rescale_Data(dataStr)181 Rescale_Data(dataStr) 174 182 175 183 End … … 177 185 //gets a valid file list (simply not the files with ".SAn" in the name) 178 186 // 179 Function A_FIT_FilePopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl187 Function FIT_FilePopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl 180 188 String ctrlName 181 189 Variable popNum 182 190 String popStr 183 191 184 String tempStr= A_filterButtonProc(ctrlName)192 String tempStr=filterButtonProc(ctrlName) 185 193 if(strlen(tempStr)==0) 186 194 tempStr = "Pick the data path" … … 200 208 //the fitted range, which is the default display after a fit is performed 201 209 // 202 Function A_ShowAllButtonProc(ctrlName) : ButtonControl210 Function ShowAllButtonProc(ctrlName) : ButtonControl 203 211 String ctrlName 204 212 205 213 //bring the FitWindow to the front and Autoscale the axes 206 DoWindow/F A_FitWindow214 DoWindow/F FitWindow 207 215 SetAxis/A 208 216 End … … 213 221 // 214 222 // dataStr is the root:folder: of the data that was loaded 215 Function A_Rescale_Data(dataStr)223 Function Rescale_Data(dataStr) 216 224 String dataStr 217 225 218 226 //Scaling exponents and background value 219 227 Variable pow_a,pow_b,pow_c,bkg 220 ControlInfo/W= A_FitPanel expa228 ControlInfo/W=FitPanel expa 221 229 pow_a = V_value 222 ControlInfo/W= A_FitPanel expb230 ControlInfo/W=FitPanel expb 223 231 pow_b = V_value 224 ControlInfo/W= A_FitPanel expc232 ControlInfo/W=FitPanel expc 225 233 pow_c = V_value 226 ControlInfo/W= A_FitPanel back234 ControlInfo/W=FitPanel back 227 235 bkg = V_value 228 236 … … 241 249 endif 242 250 //if q^c is the x-scaling, c must be be within limits and also non-zero 243 ControlInfo/W= A_FitPanel xModel251 ControlInfo/W=FitPanel xModel 244 252 If (cmpstr("q^c",S_Value) == 0) 245 253 if(pow_c == 0) … … 265 273 String xlabel,ylabel,xstr,ystr 266 274 //check for proper y-scaling selection, make the necessary waves 267 ControlInfo/W= A_FitPanel yModel275 ControlInfo/W=FitPanel yModel 268 276 ystr = S_Value 269 277 // print "ystr = ",ystr … … 365 373 Variable low,high 366 374 367 ControlInfo/W= A_FitPanel lolim375 ControlInfo/W=FitPanel lolim 368 376 low = V_value 369 ControlInfo/W= A_FitPanel uplim377 ControlInfo/W=FitPanel uplim 370 378 high = V_value 371 379 if ((high<low) || (high==low)) … … 374 382 endif 375 383 376 ControlInfo/W= A_FitPanel xModel384 ControlInfo/W=FitPanel xModel 377 385 xstr = S_Value 378 386 do … … 422 430 423 431 // String cleanLastFileName = "root:"+CleanupName(gLastFileName,0) 424 If(WinType(" A_FitWindow") == 0)432 If(WinType("FitWindow") == 0) 425 433 Display /W=(5,42,480,400)/K=1 yAxisWave vs xAxisWave 426 434 ModifyGraph mode=3,standoff=0,marker=8,opaque=1 427 435 ErrorBars/T=0 yAxisWave Y,wave=(yErrWave,yErrWave) 428 DoWindow/C A_FitWindow436 DoWindow/C FitWindow 429 437 else 430 438 //window already exists, just bring to front for update 431 DoWindow/F A_FitWindow439 DoWindow/F FitWindow 432 440 // remove old text boxes 433 441 TextBox/K/N=text_1 … … 439 447 TextBox/C/N=textLabel/A=RB "File = "+baseStr 440 448 //clear the old fit from the window, if it exists 441 RemoveFromGraph/W= A_FitWindow/Z fit_yAxisWave449 RemoveFromGraph/W=FitWindow/Z fit_yAxisWave 442 450 443 451 // add the cursors if desired... 444 452 //see if the user wants to use the data specified by the cursors - else use numerical values 445 453 446 ControlInfo/W= A_FitPanel check0 //V_value = 1 if it is checked, meaning yes, use cursors454 ControlInfo/W=FitPanel check0 //V_value = 1 if it is checked, meaning yes, use cursors 447 455 yes_cursors = V_value 448 456 449 DoWindow/F A_FitWindow457 DoWindow/F FitWindow 450 458 ShowInfo 451 459 if(yes_cursors) … … 461 469 if(V_flag == 1) //level NOT found 462 470 DoAlert 0,"Lower q-limit not in experimental q-range. Re-enter a better value" 463 //DoWindow/K A_FitWindow471 //DoWindow/K FitWindow 464 472 //Abort 465 473 endif … … 469 477 if(V_flag == 1) 470 478 DoAlert 0,"Upper q-limit not in experimental q-range. Re-enter a better value" 471 //DoWindow/K A_FitWindow479 //DoWindow/K FitWindow 472 480 //Abort 473 481 endif … … 489 497 //and the results are plotted 490 498 // function works in root level data folder (where the loaded 1-d data will be) 491 Function A_DispatchModel(GoFit) : ButtonControl499 Function DispatchModel(GoFit) : ButtonControl 492 500 String GoFit 493 501 494 502 //check for the FitWindow - to make sure that there is data to fit 495 If(WinType(" A_FitWindow") == 0) //if the window doesn't exist503 If(WinType("FitWindow") == 0) //if the window doesn't exist 496 504 Abort "You must Load and Plot a File before fitting the data" 497 505 endif 498 506 499 507 // rescale the data, to make sure it's as selected on the panel 500 ControlInfo/W= A_FitPanel $"ywave"508 ControlInfo/W=FitPanel $"ywave" 501 509 String partialName = CleanupName(S_value,0) 502 A_Rescale_Data("root:"+partialName+":")510 Rescale_Data("root:"+partialName+":") 503 511 504 512 // now go do the fit … … 507 515 Variable low,high 508 516 509 ControlInfo/W= A_FitPanel lolim517 ControlInfo/W=FitPanel lolim 510 518 low = V_value 511 ControlInfo/W= A_FitPanel uplim519 ControlInfo/W=FitPanel uplim 512 520 high = V_value 513 521 if ((high<low) || (high==low)) … … 518 526 //try including residuals on the graph /R=residWave, explicitly place on new axis 519 527 //if only /R used, residuals are automatically placed on graph 520 // -- NOTE that A_Rescale_Data() calculates the weighting wave as 1/err (like the old days) so the flag is correctly528 // -- NOTE that Rescale_Data() calculates the weighting wave as 1/err (like the old days) so the flag is correctly 521 529 // /I=0, not /I=1 522 530 … … 530 538 //ystr and xstr are the axis strings - filter with a do-loop 531 539 String ystr="",xstr="" 532 //ControlInfo/W= A_FitPanel ywave540 //ControlInfo/W=FitPanel ywave 533 541 Wave xw = $("root:"+partialName+":"+partialName + "_q") 534 ControlInfo/W= A_FitPanel yModel542 ControlInfo/W=FitPanel yModel 535 543 ystr = S_Value 536 ControlInfo/W= A_FitPanel xModel544 ControlInfo/W=FitPanel xModel 537 545 xstr = S_Value 538 546 … … 555 563 do 556 564 If (cmpstr("I",ystr) == 0) 557 textstr_3 = "I(q=0) = " + num2str(W_coef[0]) 565 textstr_3 = "I(q=0) = " + num2str(W_coef[0]) +" ± "+num2str(W_sigma[0]) 558 566 break 559 567 endif 560 568 If (cmpstr("ln(I)",ystr) == 0) 561 textstr_3 = "I(q=0) = " + num2str(exp(W_coef[0])) 569 izerr = abs(exp(W_coef[0]) - exp(W_coef[0]+W_sigma[0])) 570 textstr_3 = "I(q=0) = " + num2str(exp(W_coef[0]))+" ± " + num2str(izerr) 562 571 if(cmpstr("q^2",xstr) == 0) //then a Guinier plot for a sphere (3-d) 563 572 rg = sqrt(-3*W_coef[1]) … … 593 602 endif 594 603 If (cmpstr("1/sqrt(I)",ystr) == 0) 595 textstr_3 = "I(q=0) = " + num2str((W_coef[0])^2) 604 izerr = abs( (W_coef[0])^-2 - (W_coef[0]+W_sigma[0])^-2 ) 605 textstr_3 = "I(q=0) = " + num2str((W_coef[0])^-2)+" ± " + num2str(izerr) 596 606 break 597 607 endif … … 623 633 while(0) 624 634 //kill the old textboxes, if they exist 625 TextBox/W= A_FitWindow/K/N=text_1626 TextBox/W= A_FitWindow/K/N=text_2627 TextBox/W= A_FitWindow/K/N=text_3635 TextBox/W=FitWindow/K/N=text_1 636 TextBox/W=FitWindow/K/N=text_2 637 TextBox/W=FitWindow/K/N=text_3 628 638 // write the new text boxes 629 TextBox/W= A_FitWindow/N=text_1/A=LT textstr_1630 TextBox/W= A_FitWindow/N=text_2/A=LC textstr_2639 TextBox/W=FitWindow/N=text_1/A=LT textstr_1 640 TextBox/W=FitWindow/N=text_2/A=LC textstr_2 631 641 If (cmpstr("",textstr_3) != 0) //only display textstr_3 if it isn't null 632 TextBox/W= A_FitWindow/N=text_3/A=LB textstr_3642 TextBox/W=FitWindow/N=text_3/A=LB textstr_3 633 643 endif 634 644 635 645 //adjust the plot range to reflect the actual fitted range 636 646 //cursors are already on the graph, done by Rescale_Data() 637 A _AdjustAxisToCursors()647 AdjustAxisToCursors() 638 648 639 649 End … … 643 653 // 644 654 // will expand the scale to show an extra 5 points in each direction (if available) 645 Function A _AdjustAxisToCursors()646 647 DoWindow/F A_FitWindow655 Function AdjustAxisToCursors() 656 657 DoWindow/F FitWindow 648 658 WAVE xAxisWave = root:xAxisWave 649 659 WAVE yAxisWave = root:yAxisWave … … 651 661 Variable extraPts = 5, num=numpnts(xAxisWave) 652 662 653 String csrA = CsrInfo(A ," A_FitWindow")654 String csrB = CsrInfo(B ," A_FitWindow")663 String csrA = CsrInfo(A ,"FitWindow") 664 String csrB = CsrInfo(B ,"FitWindow") 655 665 656 666 //x-levels, these are monotonic … … 720 730 // Windows, where the data file must be .txt (and possibly OSX) 721 731 // 722 Function/S A_filterButtonProc(ctrlName)732 Function/S filterButtonProc(ctrlName) 723 733 String ctrlName 724 734 … … 746 756 endfor 747 757 //remove VAX version numbers 748 newList = A_RemoveVersNumsFromList(newList)758 newList = RemoveVersNumsFromList(newList) 749 759 //sort 750 760 newList = SortList(newList,";",0) … … 755 765 756 766 767 //////////////////////////////////////// FIT RPA /////////////////////////////////////////// 768 //**************************************** 769 //procedures for creating and initializing the FITRPA panel 770 //global variables (numerical only) are kept in root:myGlobals:FITRPA folder, 771 //created as needed 772 // 773 // very similar in function to the FIT panel 774 // 775 Proc OpenFitRPAPanel() 776 If(WinType("FitRPAPanel") == 0) 777 //create the necessary data folder 778 NewDataFolder/O root:myGlobals:FITRPA 779 //initialize the values 780 Variable/G root:myGlobals:FITRPA:gLolim = 0.02 781 Variable/G root:myGlobals:FITRPA:gUplim = 0.04 782 Variable/G root:myGlobals:FITRPA:gBack = 0 783 Variable/G root:myGlobals:FITRPA:gLambda = 6.0 784 PathInfo/S catPathName 785 String localpath = S_path 786 if (V_flag == 0) 787 //path does not exist - no folder selected 788 String/G root:myGlobals:FITRPA:gPathStr = "no folder selected" 789 else 790 String/G root:myGlobals:FITRPA:gPathStr = localpath 791 endif 792 String/G root:myGlobals:FITRPA:gDataPopList = "none" 793 FitRPAPanel() 794 else 795 //window already exists, just bring to front for update 796 DoWindow/F FitRPAPanel 797 endif 798 //pop the menu 799 FilePopMenuProc("",1,"") 800 End 801 802 //used on the fit/rpa panel to select the path for the data 803 // - automatically pops the file list after the new path selection 804 Function FITRPAPickPathButton(ctrlName) : ButtonControl 805 String ctrlName 806 807 Variable err = A_PickPath() //sets global path value 808 SVAR pathStr = root:myGlobals:gCatPathStr 809 810 //set the global string for NSORT to the selected pathname 811 String/G root:myGlobals:FITRPA:gPathStr = pathStr 812 813 //call the popup menu proc's to re-set the menu choices 814 FilePopMenuProc("filePopup",1,"") 815 816 End 817 818 //gets a valid file list (simply not the files with ".SAn" in the name) 819 // 820 Function FilePopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl 821 String ctrlName 822 Variable popNum 823 String popStr 824 825 String tempStr=ReducedDataFileList(ctrlName) 826 if(strlen(tempStr)==0) 827 tempStr = "Pick the data path" 828 Endif 829 String/G root:myGlobals:FITRPA:gDataPopList = tempStr //function is in NSORT.ipf 830 ControlUpdate filePopup 831 832 End 833 834 835 836 // window recreation macro to draw the fit/rpa panel 837 //globals and data folders must be present before drawing panel 838 // 839 Window FitRPAPanel() 840 841 String angst = root:myGlobals:gAngstStr 842 PauseUpdate; Silent 1 // building window... 843 NewPanel /W=(250,266,591,579)/K=1 844 ModifyPanel cbRGB=(32768,54528,65280) 845 ModifyPanel fixedSize=1 846 SetDrawLayer UserBack 847 SetDrawEnv fstyle= 1 848 DrawText 81,19,"Select Experimental Data" 849 SetDrawEnv fstyle= 1 850 DrawText 97,102,"q-range to fit ("+angst+"^-1)" 851 SetDrawEnv fstyle= 1 852 DrawText 87,239,"Select the fit parameters" 853 SetDrawEnv fillpat= 0 854 DrawRect 1,103,338,224 855 SetDrawEnv fillpat= 0 856 DrawRect 1,20,337,83 857 SetDrawEnv fillpat= 0 858 DrawRect 2,241,337,275 859 // Button PathButton,pos={6,26},size={80,20},proc=FitRPAPickPathButton,title="Pick Path" 860 // Button PathButton,help={"Select the local path to the folder containing your SANS data"} 861 // SetVariable setPath,pos={95,29},size={240,17},title="Path:" 862 // SetVariable setPath,help={"The current path to the local folder with SANS data"} 863 // SetVariable setPath,fSize=10 864 // SetVariable setPath,limits={0,0,0},value= root:myGlobals:FITRPA:gPathStr 865 PopupMenu filePopup,pos={8,30},size={96,21},proc=FilePopMenuProc,title="Files" 866 PopupMenu filePopup,help={"Select the data file to load."} 867 PopupMenu filePopup,mode=5,popvalue="none",value= #"root:myGlobals:FITRPA:gDataPopList" 868 SetVariable lambda,pos={111,250},size={120,18},title="Lambda ("+angst+")" 869 SetVariable lambda,help={"This sets the wavelength for the multiple scattering corrections."} 870 SetVariable lambda,limits={0,10,0},value= root:myGlobals:FITRPA:gLambda 871 Button GoFit,pos={60,286},size={80,20},proc=DoFITRPA,title="Do the Fit" 872 Button GoFit,help={"This button will do the specified fit using the selections in this panel"} 873 SetVariable lolim,pos={82,113},size={134,28},title="Lower Limit" 874 SetVariable lolim,help={"Enter the lower q-limit to perform the fit ("+angst+"^-1)"} 875 SetVariable lolim,limits={0,5,0},value= root:myGlobals:FITRPA:gLolim 876 SetVariable uplim,pos={80,140},size={134,28},title="Upper Limit" 877 SetVariable uplim,help={"Enter the upper q-limit to perform the fit ("+angst+"^-1)"} 878 SetVariable uplim,limits={0,5,0},value= root:myGlobals:FITRPA:gUplim 879 CheckBox RPA_check0,pos={64,198},size={190,20},title="Use cursor range from FitWindow" 880 CheckBox RPA_check0,help={"Checking this will perform a fit between the cursors on the graph in FitWindow and ignore the numerical limits typed above"},value=0 881 PopupMenu model,pos={3,249},size={101,21},title="Standard" 882 PopupMenu model,help={"This popup selects which standard should be used to fit this data"} 883 PopupMenu model,mode=1,popvalue="B",value= #"\"B;C;AS\"" 884 Button sh_all,pos={82,168},size={130,20},proc=ShowAllButtonProc,title="Show Full q-range" 885 Button sh_all,help={"Use this to show the entire q-range of the data rather than just the fitted range."} 886 Button loadButton,pos={20,55},size={70,20},proc=FITRPA_Load_Proc,title="Load File" 887 Button loadButton,help={"After choosing a file, load it into memory and plot it with this button."} 888 Button helpButton,pos={270,55},size={25,20},proc=showFITHelp,title="?" 889 Button helpButton,help={"Show help file for RPA fitting"} 890 Button DoneButton,pos={200,286},size={50,20},proc=FITRPADoneButton,title="Done" 891 Button DoneButton,help={"This button will close the panel and the associated graph"} 892 EndMacro 893 894 895 Proc FITRPADoneButton(ctrlName) : ButtonControl 896 String ctrlName 897 DoWindow/K FitWindow 898 DoWindow/K FitRPAPanel 899 end 900 901 //dispatches the fit to the appropriate model 902 //and the appropriate range, based on selections in the panel 903 // 904 Proc DoFITRPA(ctrlName) : ButtonControl 905 String ctrlName 906 // 907 String cleanLastFileName = CleanupName(root:Packages:NIST:gLastFileName,0) 908 String tmpStr = "root:"+cleanLastFileName+":"+cleanLastFileName 909 910 Duplicate/O $(tmpStr+"_q") xAxisWave 911 Duplicate/O $(tmpStr+"_i") yAxisWave 912 Duplicate/O $(tmpStr+"_s") yErrWave,yWtWave,residWave 913 914 yWtWave = 1/yErrWave 915 916 String xlabel = "q (A^-1)" 917 String ylabel = "Intensity" 918 //Check to see if the FitWindow exists 919 //Plot the data in a FitWindow 920 If(WinType("FitWindow") == 0) 921 Display /W=(5,42,480,400)/K=1 yAxisWave vs xAxisWave 922 ModifyGraph mode=3,standoff=0,marker=8 923 ErrorBars/T=0 yAxisWave Y,wave=(yErrWave,yErrWave) 924 DoWindow/C FitWindow 925 ShowInfo 926 else 927 //window already exists, just bring to front for update 928 DoWindow/F FitWindow 929 // remove old text boxes 930 TextBox/K/N=text_1 931 TextBox/K/N=text_2 932 TextBox/K/N=text_3 933 endif 934 935 //see if the user wants to use the data specified by the cursors - else use numerical values 936 Variable xlow,xhigh,ylow,yhigh,yes_cursors 937 ControlInfo/W=FitRPAPanel RPA_check0 //V_value = 1 if it is checked, meaning yes, use cursors 938 yes_cursors = V_value 939 940 ControlInfo/W=FitRPAPanel lolim 941 xlow = V_value 942 ControlInfo/W=FitRPAPanel uplim 943 xhigh = V_value 944 if(yes_cursors) 945 xlow = xAxisWave[xcsr(A)] 946 xhigh = xAxisWave[xcsr(B)] 947 if(xlow > xhigh) 948 xhigh = xlow 949 xlow = xAxisWave[xcsr(B)] 950 endif 951 // Print "xlow,xhigh = ",xlow,xhigh 952 ylow = yAxisWave[xcsr(A)] 953 yhigh = yAxisWave[xcsr(B)] 954 if(ylow > yhigh) 955 ylow=yhigh 956 yhigh = yAxisWave[xcsr(A)] 957 endif 958 else 959 FindLevel/P/Q xAxisWave, xlow 960 if(V_flag == 1) //level NOT found 961 DoAlert 0,"Lower q-limit not in experimental q-range. Re-enter a better value" 962 DoWindow/K FitWindow 963 Abort 964 endif 965 Cursor/P A, yAxisWave,trunc(V_LevelX)+1 966 ylow = yAxisWave[V_LevelX] 967 FindLevel/P/Q xAxisWave, xhigh 968 if(V_flag == 1) 969 DoAlert 0,"Upper q-limit not in experimental q-range. Re-enter a better value" 970 DoWindow/K FitWindow 971 Abort 972 endif 973 Cursor/P B, yAxisWave,trunc(V_LevelX) 974 yhigh = yAxisWave[V_LevelX] 975 if(ylow > yhigh) 976 yhigh=ylow 977 ylow = yAxisWave[V_levelX] 978 endif 979 endif //if(V_value) 980 SetAxis bottom,xlow,xhigh 981 982 // print "ylow,yhigh",ylow,yhigh 983 984 //Get the rest of the data from the panel 985 //such as which standard, the wavelength 986 ControlInfo/W=FitRPAPanel model 987 988 //find the model name 989 String modelName = S_value 990 991 Variable first_guess, seglength,iabs,iarb,thick 992 Make/D/O/N=2 fitParams 993 994 seglength = 6.8 995 996 first_guess = 1.0 997 fitParams[0] = first_guess 998 fitParams[1] = seglength 999 1000 If (cmpstr(modelName,"B")==0) 1001 iabs = BStandardFunction(fitParams,xlow) 1002 fitParams[0] = yhigh/iabs 1003 // Print fitParams[0],fitParams[1] 1004 FuncFit BStandardFunction fitParams yAxisWave(xcsr(A),xcsr(B)) /X=xAxisWave /W=yWtWave /D 1005 iarb = BStandardFunction(fitParams, 0.0) 1006 iabs = iarb/fitParams[0] 1007 thick = 0.153 1008 endif 1009 If (cmpstr(modelName,"C")==0) 1010 iabs = CStandardFunction(fitParams,xlow) 1011 fitParams[0] = yhigh/iabs 1012 FuncFit CStandardFunction fitParams yAxisWave(xcsr(A),xcsr(B)) /X=xAxisWave /W=yWtWave /D 1013 iarb = CStandardFunction(fitParams, 0.0) 1014 iabs = iarb/fitParams[0] 1015 thick= 0.153 1016 endif 1017 If (cmpstr(modelName,"AS")==0) 1018 iabs = ASStandardFunction(fitParams,xlow) 1019 fitParams[0] = yhigh/iabs 1020 FuncFit ASStandardFunction fitParams yAxisWave(xcsr(A),xcsr(B)) /X=xAxisWave /W=yWtWave /D 1021 iarb = ASStandardFunction(fitParams, 0.0) 1022 iabs = iarb/fitParams[0] 1023 thick = 0.1 1024 endif 1025 ModifyGraph rgb(fit_yAxisWave)=(0,0,0) 1026 Label left ylabel 1027 Label bottom xlabel //E denotes "scaling" - may want to use "units" instead 1028 1029 ControlInfo/W=FitRPAPanel lambda 1030 1031 Variable cor_mult = 1.0 + 2.2e-4*V_Value^2 1032 1033 //WAVE W_coef=W_coef 1034 //WAVE W_sigma=W_sigma 1035 String textstr_1,textstr_2,textstr_3 = "" 1036 textstr_1 = "Scaling Parameter: "+num2str(fitParams[0])+" ± "+num2str(W_sigma[0]) 1037 textstr_1 += "\rSegment Length: "+num2str(fitParams[1])+" ± "+num2str(W_sigma[1]) 1038 textstr_1 += "\rChi-Squared = " + num2str(V_chisq/(V_npnts - 3)) 1039 1040 textstr_2 = "Cross section at q=0: Iabs(0) = "+num2str(iabs)+"cm\S-1\M" 1041 textstr_2 += "\rData extrapolated to q=0: Im(0) = "+num2str(iarb)+" Counts/(10\S8\M Mon cts)" 1042 textstr_2 += "\rData corrected for multiple scattering: I(0) = "+num2str(iarb/cor_mult)+" Counts/(10\S8\M Mon cnts)" 1043 1044 textstr_3 = "In the ABS protocol, " 1045 textstr_3 += "\rStandard Thickness, d = "+num2str(thick)+"cm" 1046 textstr_3 += "\rI(0), Iarb(0) = "+num2str(iarb/cor_mult)+"Counts/(10\S8\M Mon cts)" 1047 textstr_3 += "\rStandard Cross Section, Iabs(0) = "+num2str(iabs)+"cm\S-1\M" 1048 TextBox/K/N=text_1 1049 TextBox/K/N=text_2 1050 TextBox/K/N=text_3 1051 TextBox/N=text_2/A=RT textstr_2 1052 TextBox/N=text_3/A=RC textstr_3 1053 TextBox/N=text_1/A=RB textstr_1 1054 1055 End 1056 1057 //loads the file selected in the popup for fitting with POL 1058 //standard functions. Reads the wavelength from the header, using 1059 //6 A as the default 1060 //plots the data in FitWindow after reading the file 1061 //updates lambda and full q-range on the Panel 1062 // 1063 Proc FITRPA_Load_Proc(ctrlName): ButtonControl 1064 String ctrlName 1065 //Load the data 1066 String tempName="",partialName="" 1067 Variable err 1068 ControlInfo $"filePopup" 1069 //find the file from the partial filename 1070 If( (cmpstr(S_value,"")==0) || (cmpstr(S_value,"none")==0) ) 1071 //null selection, or "none" from any popup 1072 Abort "no file selected in popup menu" 1073 else 1074 //selection not null 1075 partialName = S_value 1076 //Print partialName 1077 Endif 1078 //get a valid file based on this partialName and catPathName 1079 tempName = FindValidFilename(partialName) 1080 1081 Variable lambdaFromFile=GetLambdaFromReducedData(tempName) 1082 Variable/G root:myGlobals:FITRPA:gLambda = lambdaFromFile 1083 Print "Lambda in file read as:", lambdaFromFile 1084 1085 //prepend path to tempName for read routine 1086 PathInfo catPathName 1087 tempName = S_path + tempName 1088 1089 //load in the data (into the root directory) 1090 LoadOneDDataWithName(tempName,0) 1091 //Print S_fileName 1092 //Print tempName 1093 1094 String cleanLastFileName = CleanupName(root:Packages:NIST:gLastFileName,0) 1095 String tmpStr = "root:"+cleanLastFileName+":"+cleanLastFileName 1096 1097 Duplicate/o $(tmpStr+"_q") xAxisWave 1098 Duplicate/o $(tmpStr+"_i") yAxisWave 1099 Duplicate/o $(tmpStr+"_s") yErrWave 1100 1101 Variable xmin, xmax 1102 WaveStats/Q xAxisWave 1103 root:myGlobals:FITRPA:gLolim=V_min 1104 root:myGlobals:FITRPA:gUplim=V_max 1105 ControlUpdate/W=FITRPAPanel/A 1106 1107 //Check to see if the FitWindow exists 1108 //Plot the data in a FitWindow 1109 If(WinType("FitWindow") == 0) 1110 Display /W=(5,42,480,400)/K=1 yAxisWave vs xAxisWave 1111 ModifyGraph mode=3,standoff=0,marker=8 1112 ErrorBars/T=0 yAxisWave Y,wave=(yErrWave,yErrWave) 1113 TextBox/C/N=textLabel/A=RB "File = "+cleanLastFileName 1114 DoWindow/C FitWindow 1115 ShowInfo 1116 else 1117 //window already exists, just bring to front for update 1118 DoWindow/F FitWindow 1119 TextBox/C/N=textLabel/A=RB "File = "+cleanLastFileName 1120 endif 1121 // remove old text boxes 1122 TextBox/K/N=text_1 1123 TextBox/K/N=text_2 1124 TextBox/K/N=text_3 1125 RemoveFromGraph/W=fitWindow /Z fit_yAxisWave 1126 SetAxis/A 1127 1128 //put cursors on the graph at first and last points 1129 Cursor/P A yAxisWave 0 1130 Cursor/P B yAxisWave (numpnts(yAxisWave) - 1) 1131 End 1132 1133 //Fitting function for the POL-B standards 1134 // 1135 Function BStandardFunction(parameterWave, x) 1136 Wave parameterWave; Variable x 1137 1138 //Model parameters 1139 Variable KN=4.114E-3,CH=9.613E4, CD=7.558E4, NH=1872, ND=1556 1140 Variable INC=0.32, CHIV=2.2E-6 1141 //Correction based on absolute flux measured 5/93 1142 Variable CORR = 1.1445 1143 1144 //Local variables 1145 Variable AP2,QRGH,QRGD,IABS_RPA,IABS 1146 1147 //Calculate the function here 1148 ap2=parameterWave[1]^2 1149 qrgh = x*sqrt(nh*ap2/6) 1150 qrgd = x*sqrt(nd*ap2/6) 1151 iabs_rpa = kn/(1/(ch*FIT_dbf(qrgh)) + 1/(cd*FIT_dbf(qrgd)) - chiv) 1152 iabs = corr*iabs_rpa + inc 1153 1154 //return the result 1155 return parameterWave[0]*iabs 1156 1157 End 1158 1159 //Fitting function for the POL-C standards 1160 // 1161 Function CStandardFunction(parameterWave, x) 1162 Wave parameterWave; Variable x 1163 1164 //Model parameters 1165 Variable KN=4.114E-3,CH=2.564E5, CD=1.912E5, NH=4993, ND=3937 1166 Variable INC=0.32, CHIV=2.2E-6 1167 //Correction based on absolute flux measured 5/93 1168 Variable CORR = 1.0944 1169 1170 //Local variables 1171 Variable AP2,QRGH,QRGD,IABS_RPA,IABS 1172 1173 //Calculate the function here 1174 ap2=parameterWave[1]^2 1175 qrgh = x*sqrt(nh*ap2/6) 1176 qrgd = x*sqrt(nd*ap2/6) 1177 iabs_rpa = kn/(1/(ch*FIT_dbf(qrgh)) + 1/(cd*FIT_dbf(qrgd)) - chiv) 1178 iabs = corr*iabs_rpa + inc 1179 1180 //return the result 1181 return parameterWave[0]*iabs 1182 1183 End 1184 1185 //fitting function for the POL-AS standards 1186 // 1187 Function ASStandardFunction(parameterWave, x) 1188 Wave parameterWave; Variable x 1189 1190 //Model parameters 1191 Variable KN=64.5,CH=1.0, CD=1.0, NH=766, ND=766 1192 Variable INC=0.32, CHIV=0.0 1193 1194 //Local variables 1195 Variable AP2,QRGH,QRGD,IABS_RPA,IABS 1196 1197 //Calculate the function here 1198 ap2=parameterWave[1]^2 1199 qrgh = x*sqrt(nh*ap2/6) 1200 1201 //The following lines were commented out in the fortran function 1202 //qrgd = x*sqrt(nd*ap2/6) 1203 //iabs_rpa = kn/(1/(ch*FIT_dbf(qrgh)) + 1/(cd*FIT_dbf(qrgd)) - chiv) 1204 1205 iabs_rpa = kn*FIT_dbf(qrgh) 1206 iabs = iabs_rpa + inc 1207 1208 //return the result 1209 return parameterWave[0]*iabs 1210 1211 End 1212 1213 //Debye Function used for polymer standards 1214 Function FIT_dbf(rgq) 1215 Variable rgq 1216 Variable x 1217 1218 x=rgq*rgq 1219 if (x < 5.0E-3) 1220 return 1.0 - x/3 + x^2/12 1221 else 1222 return 2*(exp(-x) + x - 1)/x^2 1223 endif 1224 End 1225 1226 1227 //////////////////////////////// EMD FIT RPA ////////////////////////////////////// 1228 1229 1230 1231 1232 757 1233 758 1234 759 1235 760 1236 //procedures to clean up after itself 1237 // 1238 // -- note that it's never going to unload if the SANS Reduction is open too - since 1239 // the old FIT_Ops was always loaded, and now points to this file. 1240 // 761 1241 Function UnloadLinFit() 762 1242 763 if (WinType(" A_FitPanel") == 7)764 DoWindow/K A_FitPanel765 endif 766 if (WinType(" A_FitWindow") != 0)767 DoWindow/K $" A_FitWindow"1243 if (WinType("FitPanel") == 7) 1244 DoWindow/K FitPanel 1245 endif 1246 if (WinType("FitWindow") != 0) 1247 DoWindow/K $"FitWindow" 768 1248 endif 769 1249 SetDataFolder root: 770 1250 Killwaves/Z xAxisWave,yAxisWave,yErrWave,residWave,yWtWave,fit_yAxisWave 771 1251 772 SVAR fileVerExt=root:Packages:NIST:SANS_ANA_EXTENSION 1252 SVAR/Z fileVerExt=root:Packages:NIST:SANS_ANA_EXTENSION 1253 if(SVAR_Exists(fileVerExt) == 0) 1254 return 0 1255 endif 1256 773 1257 String fname="LinearizedFits" 774 1258 Execute/P "DELETEINCLUDE \""+fname+fileVerExt+"\"" … … 776 1260 end 777 1261 1262 #if(exists("root:Packages:NIST:SANS_ANA_EXTENSION") != 0) 1263 //this keeps the SANS Models menu from appearing in the SANS Reduction package 778 1264 Menu "SANS Models" 779 1265 Submenu "Packages" … … 782 1268 end 783 1269 784 Function A_FIT_PickPathButtonProc(ctrlName) : ButtonControl 1270 #endif 1271 1272 Function FIT_PickPathButtonProc(ctrlName) : ButtonControl 785 1273 String ctrlName 786 1274 787 1275 A_PickPath() 788 1276 //pop the file menu 789 A_FIT_FilePopMenuProc("",1,"")790 End 1277 FIT_FilePopMenuProc("",1,"") 1278 End
Note: See TracChangeset
for help on using the changeset viewer.