Ignore:
Timestamp:
Mar 14, 2016 1:34:41 PM (7 years ago)
Author:
srkline
Message:

fixing issues with QUOKKA reduction procedures that generate errors in Igor 7

updated the QKK_NSORT file to match the new 4-file NSORT. this was a complete, direct copy of the file as there were no Ansto -specific bits.

Location:
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/QKK_ANSTO_Transmission.ipf

    r917 r986  
    208208        do 
    209209                if(cmpstr(T_Filenames[ii],"")==0 || cmpstr(S_Filenames[ii],"")==0 || cmpstr(EMP_Filenames[ii],"")==0) 
    210                         print "Row is incomplete and therefore being deleted " + T_Filenames + " " + S_Filenames + " " + EMP_Filenames 
     210                        print "Row is incomplete and therefore being deleted " + T_Filenames[ii] + " " + S_Filenames[ii] + " " + EMP_Filenames[ii] 
    211211                        DeletePoints ii,1,T_Filenames,S_Filenames,EMP_Filenames 
    212212                        ii-=1 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/QKK_ANSTO_Utils.ipf

    r908 r986  
    878878//      Print "trans = ",trans 
    879879        //nha - delete this line when multiple lambda values 
    880         trans = att 
     880        trans = att[0] 
    881881         
    882882        return trans 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/QKK_NSORT.ipf

    r908 r986  
    88// NSORT panel for combining and inter-normalizing 2 or 3 datasets 
    99// that have previously been averaged 
     10// 
     11// MAR 2016 SRK added functionality to combine 4 datasets 
    1012// 
    1113// - handles 3 or 6-column datasets 
     
    3638        MedQPopMenuProc("",1,"") 
    3739        HighQPopMenuProc("",1,"") 
     40        HighestQPopMenuProc("",1,"") 
    3841End 
    3942 
     
    4851        Variable/G root:myGlobals:NSORT:gScale1_2 = 1 
    4952        Variable/G root:myGlobals:NSORT:gScale2_3 = 1 
     53        Variable/G root:myGlobals:NSORT:gScale3_4 = 1 
    5054        // 
    5155        //save the number of points to trim from beginning/end of the data files 
     
    5761        Variable/G root:myGlobals:NSORT:gPtsBeg3 = NumVarOrDefault("root:myGlobals:NSORT:gPtsBeg3", 0 ) 
    5862        Variable/G root:myGlobals:NSORT:gPtsEnd3 = NumVarOrDefault("root:myGlobals:NSORT:gPtsEnd3", 0 ) 
     63        Variable/G root:myGlobals:NSORT:gPtsBeg4 = NumVarOrDefault("root:myGlobals:NSORT:gPtsBeg4", 0 ) 
     64        Variable/G root:myGlobals:NSORT:gPtsEnd4 = NumVarOrDefault("root:myGlobals:NSORT:gPtsEnd4", 0 ) 
    5965         
    6066        Variable/G root:myGlobals:NSORT:gColumns1 = 0 
    6167        Variable/G root:myGlobals:NSORT:gColumns2 = 0 
    6268        Variable/G root:myGlobals:NSORT:gColumns3 = 0 
     69        Variable/G root:myGlobals:NSORT:gColumns4 = 0 
    6370        Variable/G root:myGlobals:NSORT:gNormToNum = 1 
    6471        String/G root:myGlobals:NSORT:gPathStr = "" 
     
    7380Function LoadDataForNSORT(fileStr,setNum) 
    7481        String fileStr          //full path:name to a valid file 
    75         Variable setNum //number of set (used for naming) = 0, 1, or 2 (ONLY) 
     82        Variable setNum //number of set (used for naming) = 0, 1, or 2 (ONLY), (2016) 3 is now valid for 4th data set 
    7683         
    7784        Variable err=0 
     
    8491        NVAR gColumns2 = root:myGlobals:NSORT:gColumns2 
    8592        NVAR gColumns3 = root:myGlobals:NSORT:gColumns3 
     93        NVAR gColumns4 = root:myGlobals:NSORT:gColumns4 
    8694        NVAR begPts1 = root:myGlobals:NSORT:gPtsBeg1 
    8795        NVAR endPts1 = root:myGlobals:NSORT:gPtsEnd1 
     
    9098        NVAR begPts3 = root:myGlobals:NSORT:gPtsBeg3 
    9199        NVAR endPts3 = root:myGlobals:NSORT:gPtsEnd3 
    92  
     100        NVAR begPts4 = root:myGlobals:NSORT:gPtsBeg4 
     101        NVAR endPts4 = root:myGlobals:NSORT:gPtsEnd4 
     102         
    93103        String cmd 
    94104        String typStr= "", trimStr="" 
     
    118128                        begPts = begPts3 
    119129                        endPts = endPts3 
     130                        break 
     131                case 4: 
     132                        sprintf cmd , "A_LoadOneDDataToName(\"%s\",\"%s\",%d,%d)",fileStr,"HighestQSet",0,1 
     133                        Execute cmd 
     134                        typStr = "HighestQSet" 
     135                        trimStr = "TrimHighestQSet" 
     136                        begPts = begPts4 
     137                        endPts = endPts4 
    120138                        break 
    121139        endswitch 
     
    168186                        gColumns3 = numCols 
    169187                        break 
     188                case 4: 
     189                        gColumns4 = numCols 
     190                        break 
    170191        endswitch 
    171192         
     
    174195End 
    175196 
    176 Function WriteNSORTedFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,[res]) 
     197Function WriteNSORTedFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,fourthFileName,normTo,norm12,norm23,norm34,[res]) 
    177198        Wave q3,i3,sig3,res 
    178         String firstFileName,secondFileName,thirdFileName,normTo 
    179         Variable norm12,norm23 
     199        String firstFileName,secondFileName,thirdFileName,fourthfileName,normTo 
     200        Variable norm12,norm23,norm34 
    180201 
    181202        NVAR useXMLOutput = root:Packages:NIST:gXML_Write 
     
    183204        if (useXMLOutput == 1) 
    184205                if(WaveExists(res)) 
    185                         WriteNSORTedXMLFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,res=res) 
     206                        WriteNSORTedXMLFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,fourthFileName,normTo,norm12,norm23,norm34,res=res) 
    186207                else 
    187                         WriteNSORTedXMLFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23) 
     208                        WriteNSORTedXMLFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,fourthFileName,normTo,norm12,norm23,norm34) 
    188209                endif 
    189210        else 
    190211                if(WaveExists(res)) 
    191                         WriteOLDNSORTedFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,res=res) 
     212                        WriteOLDNSORTedFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,fourthFileName,normTo,norm12,norm23,norm34,res=res) 
    192213                else 
    193                         WriteOLDNSORTedFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23) 
     214                        WriteOLDNSORTedFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,fourthFileName,normTo,norm12,norm23,norm34) 
    194215                endif            
    195216        endif 
     
    198219 
    199220 
    200 Function WriteOLDNSORTedFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,normTo,norm12,norm23,[res]) 
     221Function WriteOLDNSORTedFile(q3,i3,sig3,firstFileName,secondFileName,thirdFileName,fourthFileName,normTo,norm12,norm23,norm34,[res]) 
    201222        Wave q3,i3,sig3,res 
    202         String firstFileName,secondFileName,thirdFileName,normTo 
    203         Variable norm12,norm23 
     223        String firstFileName,secondFileName,thirdFileName,fourthFileName,normTo 
     224        Variable norm12,norm23,norm34 
    204225 
    205226        Variable err=0,refNum,numCols,dialog=1 
     
    287308//      fprintf refnum, "THIRD File %s",hdr3            //new, Mar 2008 
    288309         
    289         fprintf refNum, "NSORT-ed   %s \t  +  %s\t  + %s\r\n",firstFileName, secondFileName,thirdFileName 
     310        fprintf refNum, "NSORT-ed   %s\t  +  %s\t  +  %s\t + %s\r\n",firstFileName, secondFileName,thirdFileName,fourthFileName 
    290311        fprintf refNum, "normalized to   %s\r\n",normTo 
    291         fprintf refNum, "multiplicative factor 1-2 = %12.8g\t multiplicative factor 2-3 = %12.8g\r\n",norm12,norm23 
     312        fprintf refNum, "multiplicative factor 1-2 = %12.8g\t multiplicative factor 2-3 = %12.8g\t multiplicative factor 3-4 = %12.8g\r\n",norm12,norm23,norm34 
    292313 
    293314        if (numCols == 3) 
    294                 formatStr = "%15g %15g %15g\r\n" 
     315                formatStr = "%15.4g %15.4g %15.4g\r\n" 
    295316                fprintf refnum, "The 3 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) |\r\n" 
    296317                wfprintf refnum, formatStr, q3,i3,sig3 
     
    300321                Make/O/N=(dimsize(res,0)) fs3 = res[p][2] 
    301322         
    302                 formatStr = "%15g %15g %15g %15g %15g %15g\r\n"  
     323                formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"      
    303324                fprintf refnum, "The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n" 
    304325                wfprintf refnum, formatStr, q3,i3,sig3,sigq3,qbar3,fs3 
     
    376397        KillDataFolder/Z MedQSet 
    377398        KillDataFolder/Z HighQSet 
     399        KillDataFolder/Z HighestQSet 
    378400 
    379401End 
     
    393415        Variable setNum,err 
    394416        //switch on ctrlName string - Plot_1, Plot_2, Plot_3 
    395         if(cmpstr(ctrlName,"Plot_1")==0) 
    396                 //low-q 
    397                 setNum = 1 
    398                 ControlInfo $"popup_1" 
    399         else 
    400                 if(cmpstr(ctrlName,"Plot_2")==0) 
     417         
     418        strswitch(ctrlName)     // string switch 
     419                case "Plot_1":           
     420                        //low-q 
     421                        setNum = 1 
     422                        ControlInfo/W=NSORT_Panel popup_1 
     423                        break 
     424                case "Plot_2":           
    401425                        //medium-q 
    402426                        setNum = 2 
    403                         ControlInfo $"popup_2" 
    404                 else 
     427                        ControlInfo/W=NSORT_Panel popup_2 
     428                        break 
     429                case "Plot_3":           
    405430                        //high-q 
    406431                        setNum = 3 
    407                         ControlInfo $"popup_3" 
    408                 Endif 
    409         Endif 
    410          
     432                        ControlInfo/W=NSORT_Panel popup_3 
     433                        break 
     434                case "Plot_4":           
     435                        //highest-q 
     436                        setNum = 4 
     437                        ControlInfo/W=NSORT_Panel popup_4 
     438                        break 
     439        endswitch 
     440         
     441 
    411442        //find the file from the partial filename 
    412443        If( (cmpstr(S_value,"")==0) || (cmpstr(S_value,"none")==0) ) 
     
    439470        if(WinType("NSORT_Graph")==0) 
    440471                //no window, create one 
    441                 if(cmpstr(ctrlName,"Plot_1")==0) 
    442                         //low-q 
    443                         Display/K=1 
    444                         DoWindow/C NSORT_Graph 
    445                         DisplayLowSet() 
    446                 else 
    447                         if(cmpstr(ctrlName,"Plot_2")==0) 
     472                strswitch(ctrlName)     // string switch 
     473                        case "Plot_1":           
     474                                //low-q 
     475                                Display/K=1 
     476                                DoWindow/C NSORT_Graph 
     477                                DisplayLowSet() 
     478                                break 
     479                        case "Plot_2":           
    448480                                //medium-q 
    449481                                Display/K=1 
    450482                                DoWindow/C NSORT_Graph 
    451483                                DisplayMedSet() 
    452                         else 
     484                                break 
     485                        case "Plot_3":           
    453486                                //high-q 
    454487                                Display/K=1 
    455488                                DoWindow/C NSORT_Graph 
    456489                                DisplayHighSet() 
    457                         Endif 
    458                 Endif 
     490                                break 
     491                        case "Plot_4":           
     492                                //highest-q 
     493                                Display/K=1 
     494                                DoWindow/C NSORT_Graph 
     495                                DisplayHighestSet() 
     496                                break 
     497                endswitch 
    459498                Legend 
    460499        else 
     
    463502                list = TraceNameList("NSORT_Graph",";",1) 
    464503         
    465                 if(cmpstr(ctrlName,"Plot_1")==0) 
    466                         //low-q 
    467                         isOnPlot = strsearch(list, "LowQSet_i", 0)              // isOnPlot == -1 if it is NOT found in the list 
    468                         if(isOnPlot == -1) 
    469                                 DisplayLowSet() 
    470                         Endif 
    471                 else 
    472                         if(cmpstr(ctrlName,"Plot_2")==0) 
     504                strswitch(ctrlName)     // string switch 
     505                        case "Plot_1":           
     506                                //low-q 
     507                                isOnPlot = strsearch(list, "LowQSet_i", 0)              // isOnPlot == -1 if it is NOT found in the list 
     508                                if(isOnPlot == -1) 
     509                                        DisplayLowSet() 
     510                                Endif 
     511                                break 
     512                        case "Plot_2":           
    473513                                //medium-q 
    474514                                isOnPlot = strsearch(list, "MedQSet_i", 0)              // isOnPlot == -1 if it is NOT found in the list 
     
    476516                                        DisplayMedSet() 
    477517                                Endif 
    478                         else 
     518                                break 
     519                        case "Plot_3":           
    479520                                //high-q 
    480521                                isOnPlot = strsearch(list, "HighQSet_i", 0)             // isOnPlot == -1 if it is NOT found in the list 
     
    482523                                        DisplayHighSet() 
    483524                                Endif 
    484                         Endif 
    485                 Endif 
     525                                break 
     526                        case "Plot_4":           
     527                                //highest-q 
     528                                isOnPlot = strsearch(list, "HighestQSet_i", 0)          // isOnPlot == -1 if it is NOT found in the list 
     529                                if(isOnPlot == -1) 
     530                                        DisplayHighestSet() 
     531                                Endif 
     532                                break 
     533                endswitch        
     534         
    486535        Endif 
     536         
     537         
    487538        //the stripPoints variable boxes should also update the graph, if necessary 
    488          
     539        return(0) 
     540End 
     541 
     542//adds both highest-q sets (full and trimmed) to the graph, which is  
     543//assumed to exist along with the high-q waves 
     544// 
     545Function DisplayHighestSet() 
     546        //function assumes that the window "NSORT_Graph" already exists 
     547//      DoWindow/F NSORT_Graph 
     548 
     549        SetDataFolder root:HighestQSet: 
     550        AppendToGraph/W=NSORT_Graph $"HighestQSet_i" vs $"HighestQSet_q" 
     551        ModifyGraph/W=NSORT_Graph log=1,mode=3,marker($"HighestQSet_i")=8,msize=2,rgb($"HighestQSet_i")=(65535,32896,0),opaque($"HighestQSet_i")=1 
     552        ErrorBars/W=NSORT_Graph/T=0 $"HighestQSet_i" Y,wave=($"HighestQSet_s",$"HighestQSet_s") 
     553        AppendToGraph/W=NSORT_Graph $"TrimHighestQSet_i" vs $"TrimHighestQSet_q" 
     554        ModifyGraph/W=NSORT_Graph mode($"TrimHighestQSet_i")=3,marker($"TrimHighestQSet_i")=19,msize=2,rgb($"TrimHighestQSet_i")=(65535,32896,0) 
     555        SetDataFolder root: 
    489556End 
    490557 
     
    499566        AppendToGraph/W=NSORT_Graph $"HighQSet_i" vs $"HighQSet_q" 
    500567        ModifyGraph/W=NSORT_Graph log=1,mode=3,marker($"HighQSet_i")=8,msize=2,rgb($"HighQSet_i")=(0,0,65535),opaque($"HighQSet_i")=1 
    501         ErrorBars/W=NSORT_Graph $"HighQSet_i" Y,wave=($"HighQSet_s",$"HighQSet_s") 
     568        ErrorBars/W=NSORT_Graph/T=0 $"HighQSet_i" Y,wave=($"HighQSet_s",$"HighQSet_s") 
    502569        AppendToGraph/W=NSORT_Graph $"TrimHighQSet_i" vs $"TrimHighQSet_q" 
    503570        ModifyGraph/W=NSORT_Graph mode($"TrimHighQSet_i")=3,marker($"TrimHighQSet_i")=19,msize=2,rgb($"TrimHighQSet_i")=(0,0,65535) 
     
    515582        AppendToGraph/W=NSORT_Graph $"MedQSet_i" vs $"MedQSet_q" 
    516583        ModifyGraph/W=NSORT_Graph log=1,mode=3,marker($"MedQSet_i")=8,msize=2,rgb($"MedQSet_i")=(65535,0,0),opaque($"MedQSet_i")=1 
    517         ErrorBars/W=NSORT_Graph $"MedQSet_i" Y,wave=($"MedQSet_s",$"MedQSet_s") 
     584        ErrorBars/W=NSORT_Graph/T=0 $"MedQSet_i" Y,wave=($"MedQSet_s",$"MedQSet_s") 
    518585        AppendToGraph/W=NSORT_Graph $"TrimMedQSet_i" vs $"TrimMedQSet_q" 
    519586        ModifyGraph/W=NSORT_Graph mode($"TrimMedQSet_i")=3,marker($"TrimMedQSet_i")=19,msize=2,rgb($"TrimMedQSet_i")=(65535,0,0) 
     
    531598        AppendToGraph/W=NSORT_Graph $"LowQSet_i" vs $"LowQSet_q" 
    532599        ModifyGraph/W=NSORT_Graph log=1,mode=3,marker($"LowQSet_i")=8,msize=2,rgb($"LowQSet_i")=(2,39321,1),opaque($"LowQSet_i")=1 
    533         ErrorBars/W=NSORT_Graph $"LowQSet_i" Y,wave=($"LowQSet_s",$"LowQSet_s") 
     600        ErrorBars/W=NSORT_Graph/T=0 $"LowQSet_i" Y,wave=($"LowQSet_s",$"LowQSet_s") 
    534601        AppendToGraph/W=NSORT_Graph $"TrimLowQSet_i" vs $"TrimLowQSet_q" 
    535602        ModifyGraph/W=NSORT_Graph mode($"TrimLowQSet_i")=3,marker($"TrimLowQSet_i")=19,msize=2,rgb($"TrimLowQSet_i")=(2,39321,1) 
     603        ModifyGraph tickUnit(left)=1 
    536604        SetDataFolder root: 
    537605End 
     
    558626        MedQPopMenuProc("popup_2",1,"") 
    559627        HighQPopMenuProc("popup_3",1,"") 
     628        HighestQPopMenuProc("popup_4",1,"") 
    560629         
    561630End 
     
    571640// 2 == MedQ 
    572641// 3 == HighQ 
     642// 4 == HighestQ 
    573643// 
    574644//"Plot_1" is the low-q button name 
    575645//"Plot_2" is the med-q button name 
    576646//"Plot_3" is the high-q button name 
     647//"Plot_4" is the high-q button name 
    577648// 
    578649//calling plot_0_Button() responds as if that named button were pressed 
     
    609680        NVAR Columns2 = root:myGlobals:NSORT:gColumns2 
    610681        NVAR Columns3 = root:myGlobals:NSORT:gColumns3 
    611         if( (Columns1 == 3) || (Columns2 == 3) || (Columns3 == 3) )  
     682        NVAR Columns4 = root:myGlobals:NSORT:gColumns4 
     683        if( (Columns1 == 3) || (Columns2 == 3) || (Columns3 == 3) || (Columns4 == 3))  
    612684                isAThree = 1 
    613685        endif 
    614         if( (Columns1 == 6) || (Columns2 == 6) || (Columns3 == 6) )  
     686        if( (Columns1 == 6) || (Columns2 == 6) || (Columns3 == 6) || (Columns4 == 6))  
    615687                isASix = 1 
    616688        endif 
     
    620692         
    621693        //is there just one data set? if so, then dispatch to a simpler routine, since no normalization is needed 
    622         ControlInfo/W=NSORT_Panel popup_2               //if MedQSet is "none", then so is HighQSet 
     694        ControlInfo/W=NSORT_Panel popup_2               //if MedQSet is "none", then so is HighQSet and HighestQSet 
    623695        fileStr = S_Value 
    624696        if(cmpstr(fileStr,"none") == 0) 
     
    657729                ControlInfo/W=NSORT_Panel popup_1 
    658730                if(isAThree) 
    659                         WriteNSORTedFile(lowq,lowi,lows,S_Value,"none","none",S_Value,scaleFactor,1) 
     731                        WriteNSORTedFile(lowq,lowi,lows,S_Value,"none","none","none",S_Value,scaleFactor,1,1) 
    660732                else 
    661                         WriteNSORTedFile(lowq,lowi,lows,S_Value,"none","none",S_Value,scaleFactor,1,res=lowres) 
     733                        WriteNSORTedFile(lowq,lowi,lows,S_Value,"none","none","none",S_Value,scaleFactor,1,1,res=lowres) 
    662734                endif 
    663735                //  just get the new list and return - don't actually "pop" the menu, or the selected item will change 
     
    672744        //two or more datasets, combine them 
    673745        //have they been manually or auto-normalized? 
    674         ControlInfo AutoCheck 
     746        ControlInfo/W=NSORT_Panel AutoCheck 
    675747        Variable checked = V_Value 
    676748         
     
    691763Window NSORT_Panel() 
    692764        PauseUpdate; Silent 1           // building window... 
    693         NewPanel /W=(569,69,944,485)/K=2 
     765        NewPanel /W=(569,69,944,584)//K=2 
    694766        ModifyPanel cbRGB=(49151,53155,65535) 
    695767        ModifyPanel fixedSize=1 
     
    701773        DrawLine 0,214,346,214 
    702774        DrawLine 0,295,346,295 
     775        DrawLine 0,372,347,372 
     776        DrawLine 0,460,346,460 
     777         
    703778        SetDrawEnv fstyle= 5 
    704779        DrawText 5,74,"Low Q:" 
     
    707782        SetDrawEnv fstyle= 5 
    708783        DrawText 8,234,"High Q: (or none)" 
     784        SetDrawEnv fstyle= 5 
     785        DrawText 8,314,"Highest Q: (or none)" 
    709786        SetDrawEnv fstyle= 4 
    710787        DrawText 178,75,"Delete Points?" 
     
    713790        SetDrawEnv fstyle= 4 
    714791        DrawText 184,236,"Delete Points?" 
    715         DrawLine 0,363,346,363 
    716         DrawText 31,357,"To Manually scale data, enter scale factors above" 
    717         Button NSORT_Done,pos={274,387},size={50,20},proc=NSORT_DoneButton,title="Done" 
     792        SetDrawEnv fstyle= 4 
     793        DrawText 184,316,"Delete Points?" 
     794        DrawText 31,456,"To Manually scale data, enter scale factors above" 
     795         
     796        Button NSORT_Done,pos={274,483},size={50,20},proc=NSORT_DoneButton,title="Done" 
    718797        Button NSORT_Done,help={"closes the panel"} 
    719798        Button Plot_1,pos={279,63},size={50,20},proc=Plot_0_Button,title="Plot" 
     
    723802        Button Plot_3,pos={284,223},size={50,20},proc=Plot_0_Button,title="Plot" 
    724803        Button Plot_3,help={"Plots the dataset from the popup, showing the full set as open circles and the trimmed set as solid circles"} 
     804        Button Plot_4,pos={284.00,303.00},size={50.00,20.00},proc=Plot_0_Button,title="Plot" 
     805        Button Plot_4,help={"Plots the dataset from the popup, showing the full set as open circles and the trimmed set as solid circles"} 
     806 
    725807        Button PathButton,pos={6,26},size={80,20},proc=NSORTPickPathButton,title="Pick Path" 
    726808        Button PathButton,help={"Select the local path to the folder containing your SANS data"} 
     
    739821        SetVariable end_3,fSize=10,help={"How many points to remove from the high-q end of this dataset"} 
    740822        SetVariable end_3,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gPtsEnd3 
     823        SetVariable end_4,pos={182.00,349.00},size={80.00,16.00},proc=SetBegOrEnd,title="End Pts" 
     824        SetVariable end_4,help={"How many points to remove from the high-q end of this dataset"} 
     825        SetVariable end_4,fSize=10 
     826        SetVariable end_4,limits={-inf,inf,0},value= root:myGlobals:NSORT:gPtsEnd4 
    741827        SetVariable beg_1,pos={182,79},size={80,14},proc=SetBegOrEnd,title="Beg Pts" 
    742828        SetVariable beg_1,fSize=10,help={"How many points to remove from the low-q end of this dataset"} 
     
    748834        SetVariable beg_3,fSize=10,help={"How many points to remove from the low-q end of this dataset"} 
    749835        SetVariable beg_3,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gPtsBeg3 
    750         Button DoCombine,pos={13,387},size={160,20},proc=WriteNSORTFileButton,title="Write Combined File" 
     836        SetVariable beg_4,pos={182.00,326.00},size={80.00,16.00},proc=SetBegOrEnd,title="Beg Pts" 
     837        SetVariable beg_4,help={"How many points to remove from the low-q end of this dataset"} 
     838        SetVariable beg_4,fSize=10 
     839        SetVariable beg_4,limits={-inf,inf,0},value= root:myGlobals:NSORT:gPtsBeg4 
     840        Button DoCombine,pos={13,483},size={160,20},proc=WriteNSORTFileButton,title="Write Combined File" 
    751841        Button DoCombine,help={"Combine and normalize the selected files as specifed"} 
    752         SetVariable scale_12,pos={159,305},size={160,14},proc=SetScale_12,title="Mult factor 1-2" 
     842        SetVariable scale_12,pos={159,381},size={160,14},proc=SetScale_12,title="Mult factor 1-2" 
    753843        SetVariable scale_12,fSize=10,help={"Factor that will multiply medium-q set to scale to low-q set"} 
    754844        SetVariable scale_12,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gScale1_2 
    755         SetVariable scale_23,pos={159,325},size={160,14},proc=SetScale_23,title="Mult factor 2-3" 
     845        SetVariable scale_23,pos={159,401},size={160,14},proc=SetScale_23,title="Mult factor 2-3" 
    756846        SetVariable scale_23,fSize=10,help={"Factor that will multiply high-q set to scale to medium-q set"} 
    757847        SetVariable scale_23,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gScale2_3 
     848        SetVariable scale_34,pos={159.00,421.00},size={160.00,16.00},proc=SetScale_34,title="Mult factor 3-4" 
     849        SetVariable scale_34,help={"Factor that will multiply highest-q set to scale to high-q set"} 
     850        SetVariable scale_34,fSize=10 
     851        SetVariable scale_34,limits={-inf,inf,0},value= root:myGlobals:NSORT:gScale3_4 
    758852        CheckBox check1,pos={5,105},size={160,20},proc=CheckProc,title="Normalize to this file",value=1 
    759853        CheckBox check1,help={"If checked, the combined dataset will be normalized to this dataset"} 
     
    762856        CheckBox check3,pos={4,270},size={160,20},proc=CheckProc,title="Normalize to this file",value=0 
    763857        CheckBox check3,help={"If checked, the combined dataset will be normalized to this dataset"} 
     858        CheckBox check4,pos={4.00,350.00},size={107.00,16.00},proc=CheckProc,title="Normalize to this file" 
     859        CheckBox check4,help={"If checked, the combined dataset will be normalized to this dataset"} 
     860        CheckBox check4,value= 0 
    764861        PopupMenu popup_1,pos={6,77},size={99,19},proc=LowQPopMenuProc 
    765862        PopupMenu popup_1,mode=1,value= #"root:myGlobals:NSORT:gDataPopList" 
     
    771868        PopupMenu popup_3,mode=1,value= #"root:myGlobals:NSORT:gDataPopList_3" 
    772869        PopupMenu popup_3,help={"Choose the dataset with the highest overall q-value (shortest detector distance), or NONE if no third set desired"} 
    773         CheckBox AutoCheck,pos={14,310},size={100,20},title="Auto Scale",value=0 
     870        PopupMenu popup_4,pos={6.00,319.00},size={58.00,23.00},proc=HighestQPopMenuProc 
     871        PopupMenu popup_4,help={"Choose the dataset with the highest overall q-value (shortest detector distance), or NONE if no fourth set desired"} 
     872        PopupMenu popup_4,mode=1,popvalue="none",value= #"root:myGlobals:NSORT:gDataPopList_3" 
     873        CheckBox AutoCheck,pos={14,386},size={100,20},title="Auto Scale",value=0 
    774874        CheckBox AutoCheck,help={"If checked, the scale factor will be automatically determined, if not checked, the current values in the fields will be used"} 
    775         CheckBox PreviewCheck,pos={15,369},size={74,14},title="Preview Only",value= 0 
    776         CheckBox WarningCheck,pos={111,369},size={93,14},title="Overlap warning?",value= 1 
     875        CheckBox PreviewCheck,pos={15,465},size={74,14},title="Preview Only",value= 0 
     876        CheckBox WarningCheck,pos={111,465},size={93,14},title="Overlap warning?",value= 1 
    777877EndMacro 
    778878 
     
    800900 
    801901        Variable/G root:myGlobals:NSORT:gScale2_3 = varNum 
     902End 
     903 
     904//sets the scale factor (multiplicative) between sets 3 and 4 
     905//re-sets the global variable 
     906// 
     907Function SetScale_34(ctrlName,varNum,varStr,varName) : SetVariableControl 
     908        String ctrlName 
     909        Variable varNum 
     910        String varStr 
     911        String varName 
     912 
     913        Variable/G root:myGlobals:NSORT:gScale3_4 = varNum 
    802914End 
    803915 
     
    820932                        CheckBox check2 value=1 
    821933                        CheckBox check3 value=0 
     934                        CheckBox check4 value=0 
    822935                        Variable/G root:myGlobals:NSORT:gNormToNum = 2 
    823936                        break 
     
    827940                        CheckBox check2 value=0 
    828941                        CheckBox check3 value=1 
     942                        CheckBox check4 value=0 
    829943                        Variable/G root:myGlobals:NSORT:gNormToNum = 3 
     944                        break 
     945                Endif 
     946                if(cmpstr(ctrlName,"check4") == 0) 
     947                        CheckBox check1 value=0 
     948                        CheckBox check2 value=0 
     949                        CheckBox check3 value=0 
     950                        CheckBox check4 value=1 
     951                        Variable/G root:myGlobals:NSORT:gNormToNum = 4 
    830952                        break 
    831953                Endif 
     
    834956                CheckBox check2 value=0 
    835957                CheckBox check3 value=0 
     958                        CheckBox check4 value=0 
    836959                Variable/G root:myGlobals:NSORT:gNormToNum = 1 
    837960        While(0) 
     961         
    838962        ControlUpdate/A/W=NSORT_Panel 
    839                 DoUpdate 
     963        DoUpdate 
    840964                 
    841965End 
     
    8971021 
    8981022 
     1023//when menu is popped, it gets a valid list to display and updates the control 
     1024// - will be different, since set 3 can also be "none" if only 2 sets 
     1025//are to be NSORTed 
     1026// 
     1027Function HighestQPopMenuProc(ctrlName,popNum,popStr) : PopupMenuControl 
     1028        String ctrlName 
     1029        Variable popNum 
     1030        String popStr 
     1031 
     1032        //add the option "none" to the file list (which should already end with a semicolon) 
     1033        String/G root:myGlobals:NSORT:gDataPopList_3 = "none;" +  ReducedDataFileList("") 
     1034 
     1035        ControlUpdate/W=NSORT_Panel popup_4 
     1036        if(cmpstr(popStr,"none")==0) 
     1037                RemoveFromGraph/Z HighestQSet_i,TrimHighestQSet_i               //remove the data from the graph 
     1038        Endif    
     1039        ControlInfo/W=NSORT_Panel popup_2 
     1040        if(cmpstr(S_Value,"none")==0) 
     1041                PopupMenu popup_3,win=NSORT_Panel,mode=1        //force "none" (item #1) to be the selection if medium is none 
     1042                PopupMenu popup_4,win=NSORT_Panel,mode=1        //force "none" (item #1) to be the selection if medium is none 
     1043        endif 
     1044        ControlInfo/W=NSORT_Panel popup_3 
     1045        if(cmpstr(S_Value,"none")==0) 
     1046                PopupMenu popup_4,win=NSORT_Panel,mode=1        //force "none" (item #1) to be the selection if medium is none 
     1047        endif 
     1048        return(0)        
     1049End 
     1050 
    8991051//be sure to use the "Trim.." datasets that have had the bad points removed 
    9001052//and then do the scaling based on the choices in the panel 
     
    9051057 
    9061058        NVAR normTo = root:myGlobals:NSORT:gNormToNum 
    907         Variable err=0,setNum,norm12,norm23 
    908         String fileStr="",tempName="",name1="",name2="",name3="",normToStr="" 
     1059        Variable err=0,setNum,norm12,norm23,norm34 
     1060        String fileStr="",tempName="",name1="",name2="",name3="",normToStr="",name4="" 
    9091061         
    9101062//Set the number of output columns 
     
    9141066        NVAR Columns2 = root:myGlobals:NSORT:gColumns2 
    9151067        NVAR Columns3 = root:myGlobals:NSORT:gColumns3 
    916         if( (Columns1 == 3) || (Columns2 == 3) || (Columns3 == 3) )  
     1068        NVAR Columns4 = root:myGlobals:NSORT:gColumns4 
     1069        if( (Columns1 == 3) || (Columns2 == 3) || (Columns3 == 3) || (Columns4 == 3) )  
    9171070                numOutputColumns = 3 
    9181071        else 
    919                 if( (Columns1 == 6) && (Columns2 == 6) && ((Columns3 == 0) || (Columns3 == 6)) )  
     1072                if( (Columns1 == 6) && (Columns2 == 6) && ((Columns3 == 0) || (Columns3 == 6)) || (Columns4 == 6) )  
    9201073                        numOutputColumns = 6 
    9211074                endif 
     
    9251078         
    9261079        //load file1 
    927         ControlInfo $"popup_1" 
     1080        ControlInfo/W=NSORT_Panel popup_1 
    9281081        fileStr = S_Value 
    9291082        name1 = fileStr 
     
    9391092         
    9401093        //load file2 
    941         ControlInfo $"popup_2" 
     1094        ControlInfo/W=NSORT_Panel popup_2 
    9421095        fileStr = S_Value 
    9431096        name2 = fileStr 
     
    9531106         
    9541107        //load file3 , if necessary 
    955         ControlInfo $"popup_3" 
     1108        ControlInfo/W=NSORT_Panel popup_3 
    9561109        fileStr = S_Value 
    9571110        name3 = fileStr 
     
    9701123        //////end load file3 
    9711124         
     1125        //load file4 , if necessary 
     1126        ControlInfo/W=NSORT_Panel popup_4 
     1127        fileStr = S_Value 
     1128        name4 = fileStr 
     1129        setNum = 4 
     1130        if(cmpstr(fileStr,"none") == 0) 
     1131                //do nothing 
     1132        else 
     1133                //get a valid file based on this partialName and catPathName 
     1134                tempName = FindValidFilename(fileStr) 
     1135         
     1136                //prepend path to tempName for read routine  
     1137                PathInfo catPathName 
     1138                tempName = S_path + tempName 
     1139                err = LoadDataForNSORT(tempName,setNum) 
     1140        Endif 
     1141        //////end load file4 
     1142         
     1143         
    9721144        //assign filename of file to normalize to 
    973         if(normTo == 1) 
    974                 normToStr = name1 
    975         else 
    976                 if(normTo == 2) 
     1145        switch(normTo) 
     1146                case 1: 
     1147                        normToStr = name1 
     1148                        break 
     1149                case 2: 
    9771150                        normToStr = name2 
    978                 else 
     1151                        break 
     1152                case 3: 
    9791153                        normToStr = name3 
    980                 Endif 
    981         Endif 
     1154                        break 
     1155                case 4: 
     1156                        normToStr = name4 
     1157                        break 
     1158        endswitch 
     1159 
    9821160 
    9831161        Variable n1,n2,n12,num2 
    9841162        Variable n3,n123 
     1163        Variable n4,n1234 
    9851164         
    9861165   if(numOutputColumns == 3) //Start the 3-column specific stuff here. 
     
    10701249                        ControlInfo/W=NSORT_Panel PreviewCheck 
    10711250                        if( V_Value==0 )                //if zero skip the preview and write out the file 
    1072                                 err=WriteNSORTedFile(q12,i12,sig12,name1,name2,name3,normToStr,norm12,norm23) 
     1251                                err=WriteNSORTedFile(q12,i12,sig12,name1,name2,name3,name4,normToStr,norm12,norm23,norm34) 
    10731252                        endif 
    10741253                        //cleanup waves before exiting 
     
    11601339                ControlInfo/W=NSORT_Panel PreviewCheck 
    11611340                if( V_Value==0 )                //if zero skip the preview and write out the file 
    1162                         err=WriteNSORTedFile(q123,i123,sig123,name1,name2,name3,normToStr,norm12,norm23) 
     1341                        err=WriteNSORTedFile(q123,i123,sig123,name1,name2,name3,name4,normToStr,norm12,norm23,norm34) 
    11631342                endif 
    11641343                //cleanup waves before exiting 
    11651344                KillWaves/Z q12,i12,sig12,q123,i123,sig123 
     1345                 
     1346                 
     1347                //do we need to continue, or write out the set here and stop? 
     1348                if(cmpstr(name4,"none") == 0) 
     1349                        //stop here 
     1350                        norm34 = 1              //norm34 was not used 
     1351                        Variable/G root:myGlobals:NSORT:gScale3_4 = 1 
     1352                        //If any of them have three columns write three column data 
     1353                         
     1354                        ControlInfo/W=NSORT_Panel PreviewCheck 
     1355                        if( V_Value==0 )                //if zero skip the preview and write out the file 
     1356                                err=WriteNSORTedFile(q123,i123,sig123,name1,name2,name3,name4,normToStr,norm12,norm23,norm34) 
     1357                        endif 
     1358                        //cleanup waves before exiting 
     1359                        KillWaves/Z q123,i123,sig123 
     1360                        return err 
     1361                Endif 
     1362                 
     1363                //need to add the fourth file... which was already loaded at the top of the function 
     1364                ///// 
     1365                //order points in sets 123-4, indexing overlap region 
     1366                //put result in temporary waves 
     1367                WaveStats/Q q123 
     1368                n123 = V_npnts 
     1369                WaveStats/Q $"root:HighestQSet:TrimHighestQSet_q" 
     1370                n4 = V_npnts 
     1371                n1234 = n123 + n4 
     1372                 
     1373                Make/O/N=(n1234) q1234,i1234,sig1234 
     1374                WAVE highestq = $"root:HighestQSet:TrimHighestQSet_q" 
     1375                WAVE highesti = $"root:HighestQSet:TrimHighestQSet_i" 
     1376                WAVE highests = $"root:HighestQSet:TrimHighestQSet_s" 
     1377         
     1378                q1234[0,n123-1] = q123[p] 
     1379                q1234[n12,n123+n4-1]= highestq[p-n123] 
     1380                i1234[0,n123-1] = i123[p] 
     1381                i1234[n12,n123+n4-1]= highesti[p-n123] 
     1382                sig1234[0,n123-1] = sig123[p] 
     1383                sig1234[n12,n123+n4-1]= highests[p-n123] 
     1384                 
     1385                Sort q1234, q1234,i1234,sig1234 
     1386                ///////////////// 
     1387                 
     1388                //find the maximum point number of set 2  in the overlap region 
     1389                FindLevel/P/Q highestq,(q123[n123-1]) 
     1390                num2 = trunc(V_levelX) 
     1391                //Print "num2 = ",num2 
     1392                 
     1393                if (auto) 
     1394                        //there must be overlap points to use auto-scaling 
     1395                        if(numtype(num2) != 0) 
     1396                                Abort "There are no data points in the overlap region. Either reduce the number of deleted points or use manual scaling." 
     1397                        endif 
     1398                        //do auto-scaling of data 
     1399                        norm34 = NCNR_GetScalingInOverlap(num2,q123,i123,highestq,highesti) 
     1400                        //Set the global variable for the 123 - 4 scale factor 
     1401                        Variable/G root:myGlobals:NSORT:gScale3_4 = norm34 
     1402                else 
     1403                        //use the value from the panel ( which is the global) 
     1404                        NVAR temp34 = root:myGlobals:NSORT:gScale3_4 
     1405                        norm34 = temp34 
     1406                Endif 
     1407                 
     1408// normalization 
     1409                switch (normTo) 
     1410                        case 1: 
     1411                        case 2: 
     1412                        case 3: 
     1413                                //normalize to first or second or third file, so multiply fourth by norm34 
     1414                                highesti *= norm34 
     1415                                highests *= norm34 
     1416                                break 
     1417                        case 4: 
     1418                                //normalize to FOURTH file, 123 by multiplicative factor 1/norm34 
     1419                                norm34 = 1/norm34 
     1420                                i123 *= norm34 
     1421                                sig123 *= norm34 
     1422                                // for the display, scale the trimmed sets 1 and 2 and 3 
     1423                                lowi *= norm34 
     1424                                lows *= norm34 
     1425                                medi *= norm34 
     1426                                meds *= norm34 
     1427                                highi *= norm34 
     1428                                highs *= norm34 
     1429                                break 
     1430                endswitch 
     1431                                 
     1432                ControlUpdate/A/W=NSORT_Panel 
     1433                DoUpdate 
     1434 
     1435                //Print "NSORT-ed ",name1," + ", name2, " + ", name3 
     1436                //Print "normalized to ",normTo 
     1437                //Print "multiplicative factor 1-2 = ",norm12," multiplicative factor 12 - 3 = ",norm23 
     1438                 
     1439                 
     1440                Make/O/N=(n1234) q1234,i1234,sig1234 
     1441                q1234[0,n123-1] = q123[p] 
     1442                q1234[n123,n123+n4-1]= highestq[p-n123] 
     1443                i1234[0,n123-1] = i123[p] 
     1444                i1234[n123,n123+n4-1]= highesti[p-n123] 
     1445                sig1234[0,n123-1] = sig123[p] 
     1446                sig1234[n123,n123+n4-1]= highests[p-n123] 
     1447                 
     1448                Sort q123, q123,i123,sig123 
     1449                //at this point 12 - 3 are combined 
     1450                //write out the set here and stop 
     1451         
     1452                ControlInfo/W=NSORT_Panel PreviewCheck 
     1453                if( V_Value==0 )                //if zero skip the preview and write out the file 
     1454                        err=WriteNSORTedFile(q123,i123,sig123,name1,name2,name3,name4,normToStr,norm12,norm23,norm34) 
     1455                endif 
     1456                //cleanup waves before exiting 
     1457                KillWaves/Z q12,i12,sig12,q123,i123,sig123 
     1458                 
     1459                 
     1460                 
     1461                 
    11661462                //combined dataset will already be displayed if the NSORT_Graph is open 
    11671463         
     
    11871483                WAVE lows = $"root:LowQSet:TrimLowQSet_s" 
    11881484                WAVE meds = $"root:MedQSet:TrimMedQSet_s" 
    1189 //              WAVE lowsq = $"root:LowQSet:TrimLowQSet_sq" 
    1190 //              WAVE medsq = $"root:MedQSet:TrimMedQSet_sq" 
    1191 //              WAVE lowqb = $"root:LowQSet:TrimLowQSet_qb" 
    1192 //              WAVE medqb =  $"root:MedQSet:TrimMedQSet_qb" 
    1193 //              WAVE lowfs = $"root:LowQSet:TrimLowQSet_fs" 
    1194 //              WAVE medfs = $"root:MedQSet:TrimMedQSet_fs" 
    11951485                WAVE lowres = $"root:LowQSet:TrimLowQSet_res" 
    11961486                WAVE medres = $"root:MedQSet:TrimMedQSet_res" 
     
    12081498                fs12[0,n1-1] = lowres[p][2] 
    12091499                fs12[n1,n1+n2-1]= medres[p-n1][2] 
    1210 //              res12[0,n1-1][0]=lowres[p][0] 
    1211 //              res12[n1,n1+n2-1][0]=medres[p-n1][0] 
    1212 //              res12[0,n1-1][1]=lowres[p][1] 
    1213 //              res12[n1,n1+n2-1][1]=medres[p-n1][1] 
    1214 //              res12[0,n1-1][2]=lowres[p][2] 
    1215 //              res12[n1,n1+n2-1][2]=medres[p-n1][2] 
    12161500 
    12171501                 
     
    12721556                fs12[0,n1-1] = lowres[p][2] 
    12731557                fs12[n1,n1+n2-1]= medres[p-n1][2] 
    1274 //              res12[0,n1-1][0]=lowres[p][0] 
    1275 //              res12[n1,n1+n2-1][0]=medres[p-n1][0] 
    1276 //              res12[0,n1-1][1]=lowres[p][1] 
    1277 //              res12[n1,n1+n2-1][1]=medres[p-n1][1] 
    1278 //              res12[0,n1-1][2]=lowres[p][2] 
    1279 //              res12[n1,n1+n2-1][2]=medres[p-n1][2] 
    12801558 
    12811559                 
     
    12931571                                res12[][1] = qb12[p] 
    12941572                                res12[][2] = fs12[p] 
    1295                                 err=WriteNSORTedFile(q12,i12,sig12,name1,name2,name3,normToStr,norm12,norm23,res=res12) 
     1573                                err=WriteNSORTedFile(q12,i12,sig12,name1,name2,name3,name4,normToStr,norm12,norm23,norm34,res=res12) 
    12961574                        endif 
    12971575                        // always clean up waves before exiting 
     
    13151593                WAVE highi = $"root:HighQSet:TrimHighQSet_i" 
    13161594                WAVE highs = $"root:HighQSet:TrimHighQSet_s" 
    1317 //              WAVE highsq = $"root:HighQSet:TrimHighQSet_sq" 
    1318 //              WAVE highqb = $"root:HighQSet:TrimHighQSet_qb" 
    1319 //              WAVE highfs = $"root:HighQSet:TrimHighQSet_fs" 
    13201595                WAVE highres = $"root:HighQSet:TrimHighQSet_res" 
    13211596         
    13221597         
    13231598                q123[0,n12-1] = q12[p] 
    1324                 q123[n1,n12+n3-1]= highq[p-n12] 
     1599                q123[n12,n12+n3-1]= highq[p-n12] 
    13251600                i123[0,n12-1] = i12[p] 
    1326                 i123[n1,n12+n3-1]= highi[p-n12] 
     1601                i123[n12,n12+n3-1]= highi[p-n12] 
    13271602                sig123[0,n12-1] = sig12[p] 
    1328                 sig123[n1,n12+n3-1]= highs[p-n12] 
     1603                sig123[n12,n12+n3-1]= highs[p-n12] 
    13291604                sq123[0,n12-1] = sq12[p] 
    1330                 sq123[n1,n12+n3-1]= highres[p-n12][0] 
     1605                sq123[n12,n12+n3-1]= highres[p-n12][0] 
    13311606                qb123[0,n12-1] = qb12[p] 
    1332                 qb123[n1,n12+n3-1]= highres[p-n12][1] 
     1607                qb123[n12,n12+n3-1]= highres[p-n12][1] 
    13331608                fs123[0,n12-1] = fs12[p] 
    1334                 fs123[n1,n12+n3-1]= highres[p-n12][2] 
    1335 //              res123[0,n12-1][0] = highres[p][0] 
    1336 //              res123[n1,n12+n3-1][0] = highres[p-n12][0] 
    1337 //              res123[0,n12-1][1] = highres[p][1] 
    1338 //              res123[n1,n12+n3-1][1] = highres[p-n12][1] 
    1339 //              res123[0,n12-1][2] = highres[p][2] 
    1340 //              res123[n1,n12+n3-1][2] = highres[p-n12][2] 
     1609                fs123[n12,n12+n3-1]= highres[p-n12][2] 
    13411610 
    13421611                 
     
    14001669                fs123[0,n12-1] = fs12[p] 
    14011670                fs123[n12,n12+n3-1]= highres[p-n12][2] 
    1402 //              res123[0,n12-1][0] = highres[p][0] 
    1403 //              res123[n1,n12+n3-1][0] = highres[p-n12][0] 
    1404 //              res123[0,n12-1][1] = highres[p][1] 
    1405 //              res123[n1,n12+n3-1][1] = highres[p-n12][1] 
    1406 //              res123[0,n12-1][2] = highres[p][2] 
    1407 //              res123[n1,n12+n3-1][2] = highres[p-n12][2] 
     1671 
    14081672                 
    14091673                Sort q123, q123,i123,sig123,sq123,qb123,fs123 
    14101674                //at this point 12 - 3 are combined 
    1411                 //write out the set here and stop 
     1675                 
     1676                //do we need to continue, or write out the set here and stop? 
     1677                if(cmpstr(name4,"none") == 0) 
     1678                        //stop here 
     1679                 
     1680                        ControlInfo/W=NSORT_Panel PreviewCheck 
     1681                        if( V_Value==0 )                //if zero skip the preview and write out the file 
     1682                                res123[][0] = sq123[p] 
     1683                                res123[][1] = qb123[p] 
     1684                                res123[][2] = fs123[p] 
     1685                                err=WriteNSORTedFile(q123,i123,sig123,name1,name2,name3,name4,normToStr,norm12,norm23,norm34,res=res123) 
     1686                        endif 
     1687                        // always clean up waves before exiting 
     1688                        KillWaves/Z q12,i12,sig12,q123,i123,sig123,sq123,qb123,fs123 //,res123 
     1689                        return err 
     1690                Endif 
     1691                 
     1692                // new 2016 - combine the 4th data set 
     1693 
     1694                //need to add the fourth file... which was already loaded at the top of the function 
     1695                ///// 
     1696                //order points in sets 123-4, indexing overlap region 
     1697                //put result in temporary waves 
     1698                WaveStats/Q q123 
     1699                n123 = V_npnts 
     1700                WaveStats/Q $"root:HighestQSet:TrimHighestQSet_q" 
     1701                n4 = V_npnts 
     1702                n1234 = n123 + n4 
     1703                 
     1704                Make/O/N=(n1234) q1234,i1234,sig1234,sq1234,qb1234,fs1234 
     1705                Make/O/N=(n1234,3) res1234 
     1706                WAVE highestq = $"root:HighestQSet:TrimHighestQSet_q" 
     1707                WAVE highesti = $"root:HighestQSet:TrimHighestQSet_i" 
     1708                WAVE highests = $"root:HighestQSet:TrimHighestQSet_s" 
     1709                WAVE highestres = $"root:HighestQSet:TrimHighestQSet_res" 
     1710         
     1711         
     1712                q1234[0,n123-1] = q123[p] 
     1713                q1234[n123,n123+n4-1]= highestq[p-n123] 
     1714                i1234[0,n123-1] = i123[p] 
     1715                i1234[n123,n123+n4-1]= highesti[p-n123] 
     1716                sig1234[0,n123-1] = sig123[p] 
     1717                sig1234[n123,n123+n4-1]= highests[p-n123] 
     1718                sq1234[0,n123-1] = sq123[p] 
     1719                sq1234[n123,n123+n4-1]= highestres[p-n123][0] 
     1720                qb1234[0,n123-1] = qb123[p] 
     1721                qb1234[n123,n123+n4-1]= highestres[p-n123][1] 
     1722                fs1234[0,n123-1] = fs123[p] 
     1723                fs1234[n123,n123+n4-1]= highestres[p-n123][2] 
     1724 
     1725                 
     1726                Sort q1234, q1234,i1234,sig1234,sq1234,qb1234,fs1234 
     1727                ///////////////// 
     1728                 
     1729                //find the maximum point number of set 2  in the overlap region 
     1730                FindLevel/P/Q highestq,(q123[n123-1]) 
     1731                num2 = trunc(V_levelX) 
     1732                //Print "num2 = ",num2 
     1733                 
     1734                if (auto) 
     1735                        //there must be overlap points to use auto-scaling 
     1736                        if(numtype(num2) != 0) 
     1737                                Abort "There are no data points in the overlap region. Either reduce the number of deleted points or use manual scaling." 
     1738                        endif 
     1739                        //do auto-scaling of data 
     1740                        norm34 = NCNR_GetScalingInOverlap(num2,q123,i123,highestq,highesti) 
     1741                        //Set the global variable for the 12 - 3 scale factor 
     1742                        Variable/G root:myGlobals:NSORT:gScale3_4 = norm34 
     1743                else 
     1744                        //use the value from the panel ( which is the global) 
     1745                        NVAR temp34 = root:myGlobals:NSORT:gScale3_4 
     1746                        norm34 = temp34 
     1747                Endif 
     1748 
     1749// normalization 
     1750                switch (normTo) 
     1751                        case 1: 
     1752                        case 2: 
     1753                        case 3: 
     1754                                //normalize to first or second or third file, so multiply fourth by norm34 
     1755                                highesti *= norm34 
     1756                                highests *= norm34 
     1757                                break 
     1758                        case 4: 
     1759                                //normalize to FOURTH file, 123 by multiplicative factor 1/norm34 
     1760                                norm34 = 1/norm34 
     1761                                i123 *= norm34 
     1762                                sig123 *= norm34 
     1763                                // for the display, scale the trimmed sets 1 and 2 and 3 
     1764                                lowi *= norm34 
     1765                                lows *= norm34 
     1766                                medi *= norm34 
     1767                                meds *= norm34 
     1768                                highi *= norm34 
     1769                                highs *= norm34 
     1770                                break 
     1771                endswitch 
     1772                 
     1773         
     1774                //Print "NSORT-ed ",name1," + ", name2, " + ", name3 
     1775                //Print "normalized to ",normTo 
     1776                //Print "multiplicative factor 1-2 = ",norm12," multiplicative factor 12 - 3 = ",norm23 
     1777                ControlUpdate/A/W=NSORT_Panel 
     1778                DoUpdate 
     1779                 
     1780                Make/O/N=(n1234) q1234,i1234,sig1234 
     1781                Make/O/N=(n1234,3) res1234 
     1782                q1234[0,n123-1] = q123[p] 
     1783                q1234[n123,n123+n4-1]= highestq[p-n123] 
     1784                i1234[0,n123-1] = i123[p] 
     1785                i1234[n123,n123+n4-1]= highesti[p-n123] 
     1786                sig1234[0,n123-1] = sig123[p] 
     1787                sig1234[n123,n123+n4-1]= highests[p-n123] 
     1788                sq1234[0,n123-1] = sq123[p] 
     1789                sq1234[n123,n123+n4-1]= highestres[p-n123][0] 
     1790                qb1234[0,n123-1] = qb123[p] 
     1791                qb1234[n123,n123+n4-1]= highestres[p-n123][1] 
     1792                fs1234[0,n123-1] = fs123[p] 
     1793                fs1234[n123,n123+n4-1]= highestres[p-n123][2] 
     1794                 
     1795                Sort q1234, q1234,i1234,sig1234,sq1234,qb1234,fs1234 
     1796                //at this point 123 - 4 are combined 
     1797                 
     1798//write out the set here and stop 
     1799                        //stop here 
    14121800         
    14131801                ControlInfo/W=NSORT_Panel PreviewCheck 
    14141802                if( V_Value==0 )                //if zero skip the preview and write out the file 
    1415                         res123[][0] = sq123[p] 
    1416                         res123[][1] = qb123[p] 
    1417                         res123[][2] = fs123[p] 
    1418                         err=WriteNSORTedFile(q123,i123,sig123,name1,name2,name3,normToStr,norm12,norm23,res=res123) 
     1803                        res1234[][0] = sq1234[p] 
     1804                        res1234[][1] = qb1234[p] 
     1805                        res1234[][2] = fs1234[p] 
     1806                        err=WriteNSORTedFile(q1234,i1234,sig1234,name1,name2,name3,name4,normToStr,norm12,norm23,norm34,res=res1234) 
    14191807                endif 
    1420                 //cleanup waves before exiting 
    1421                 KillWaves/Z q12,i12,sig12,q123,i123,sig123,sq123,qb123,fs123 //,res123 
     1808                // always clean up waves before exiting 
     1809                KillWaves/Z q123,i123,sig123,q1234,i1234,sig1234,sq1234,qb1234,fs1234 //,res1234 
     1810                return err 
     1811 
    14221812                //combined dataset will already be displayed if the NSORT_Graph is open 
    14231813         
    14241814                //////////////// 
    14251815                return err 
    1426    endif // End the 6-column specific stuff here 
    1427          
    1428 End 
     1816   endif // End the if(6-column) specific stuff here 
     1817         
     1818         
     1819End 
     1820 
     1821 
     1822 
    14291823 
    14301824 
     
    14891883End 
    14901884 
     1885///////////////////////////////////////////////////////////// 
     1886// testing, may speed up NSORT, NCNR-specific naming scheme of  
     1887// run numbers and a run prefix 
     1888// 
     1889// it is assumed that you are combining data from the current reduction session, 
     1890// so that the XML y/n hasn't changed. 
     1891// 
     1892// updated to use 4 files 
     1893// 
     1894// TODO: 
     1895// -- still assuming ABS 
     1896// 
     1897Function Set4NSORTFiles(low,med,hi,highest,pref) 
     1898        Variable low,med,hi,highest 
     1899        String pref 
     1900         
     1901        //make strings from the numbers 
     1902        String absStr="",ext 
     1903        Variable popNum 
     1904        DoWindow/F NSORT_Panel 
     1905         
     1906        SVAR lowQPopStr = root:myGlobals:NSORT:gDataPopList 
     1907        SVAR medHiQPopStr = root:myGlobals:NSORT:gDataPopList_3 
     1908         
     1909        NVAR useXMLOutput = root:Packages:NIST:gXML_Write 
     1910        if(useXMLOutput) 
     1911                ext = ".ABSx" 
     1912        else 
     1913                ext = ".ABS" 
     1914        endif 
     1915         
     1916        //lowQ menu 
     1917        absStr = pref+RunDigitString(low)+ext 
     1918        popNum = WhichListItem(absStr,lowQPopStr,";",0) 
     1919        if(popNum == -1) 
     1920                Abort "Could not find file: " + absStr +" aborting...  Be sure that your output format is the same as the input" 
     1921        endif 
     1922        popNum += 1             // add 1 to get the item number 
     1923        PopupMenu popup_1,win=NSORT_Panel,mode=(popNum) 
     1924         
     1925        //medQ (a different list for the popup) 
     1926        absStr = pref+RunDigitString(med)+ext 
     1927        popNum = WhichListItem(absStr,medHiQPopStr,";",0) 
     1928        if(popNum == -1) 
     1929                Abort "Could not find file: "+absStr+" aborting...  Be sure that your output format is the same as the input" 
     1930        endif 
     1931        popNum += 1             // add 1 to get the item number 
     1932        PopupMenu popup_2,win=NSORT_Panel,mode=(popNum) 
     1933         
     1934         
     1935        //highQ (same pop list as medQ) 
     1936        if(hi != 0) 
     1937                absStr = pref+RunDigitString(hi)+ext 
     1938                popNum = WhichListItem(absStr,medHiQPopStr,";",0) 
     1939                if(popNum == -1) 
     1940                        Abort "Could not find file: "+absStr+" aborting...  Be sure that your output format is the same as the input" 
     1941                endif 
     1942                popNum += 1             // add 1 to get the item number 
     1943                PopupMenu popup_3,win=NSORT_Panel,mode=(popNum) 
     1944        else 
     1945                PopupMenu popup_3,win=NSORT_Panel,mode=(1) 
     1946        endif 
     1947         
     1948        //highestQ (same pop list as medQ) 
     1949        if(highest != 0) 
     1950                absStr = pref+RunDigitString(highest)+ext 
     1951                popNum = WhichListItem(absStr,medHiQPopStr,";",0) 
     1952                if(popNum == -1) 
     1953                        Abort "Could not find file: "+absStr+" aborting...  Be sure that your output format is the same as the input" 
     1954                endif 
     1955                popNum += 1             // add 1 to get the item number 
     1956                PopupMenu popup_4,win=NSORT_Panel,mode=(popNum) 
     1957        else 
     1958                PopupMenu popup_4,win=NSORT_Panel,mode=(1) 
     1959        endif 
     1960         
     1961        return(0) 
     1962End 
     1963 
    14911964//more beta procedures - to create a table of scattering runs to combine with NSORT 
    14921965Proc CreateTableToCombine(ctrlName) 
     
    15352008                        //write to notebook that file was not found 
    15362009                        //if string is not a number, report the error 
    1537                         //if(str2num(partialName) == NaN) // will always be false [davidm] 
    15382010                        if(numtype(str2num(partialName)) == 2) 
    15392011                                str = "this file was not found: "+partialName+"\r\r" 
     
    16922164        MedQPopMenuProc("",1,"") 
    16932165        HighQPopMenuProc("",1,"") 
     2166        HighestQPopMenuProc("",1,"") 
    16942167         
    16952168//      String savedDataFolder = GetDataFolder(1)               // save 
     
    16972170        Wave MediumRun = root:myGlobals:CombineTable:MediumRun 
    16982171        Wave HighRun = root:myGlobals:CombineTable:HighRun 
     2172        Wave HighestRun = root:myGlobals:CombineTable:HighestRun 
    16992173        Wave/T prefix = root:myGlobals:CombineTable:Prefix 
    17002174        Wave/T saveName = root:myGlobals:CombineTable:saveName 
     
    17022176        Variable/G root:myGlobals:CombineTable:useTable=1 
    17032177         
    1704         Variable num=numpnts(lowRun),ii,lowFile,medFile,hiFile 
     2178        Variable num=numpnts(lowRun),ii,lowFile,medFile,hiFile,highestFile 
    17052179        String prefixStr = "" 
    17062180        Pathinfo catPathName 
     
    17122186                medFile = MediumRun[ii] 
    17132187                hiFile = highRun[ii] 
     2188                highestFile = highestRun[ii] 
    17142189                prefixStr = prefix[ii] 
    17152190                 
    1716                 Set3NSORTFiles(lowFile,medFile,hiFile,prefixStr)                //set the files and pop the NSORT popups 
     2191                Set4NSORTFiles(lowFile,medFile,hiFile,highestFile,prefixStr)            //set the files and pop the NSORT popups 
    17172192                 
    17182193                //pass the new file name in as a global (ugh!) 
     
    17832258                Wave medium = $"root:myGlobals:CombineTable:MediumRun" 
    17842259                Wave high = $"root:myGlobals:CombineTable:HighRun" 
     2260                Wave highest = $"root:myGlobals:CombineTable:HighestRun" 
    17852261                Wave/T prefix = $"root:myGlobals:CombineTable:Prefix" 
    17862262                Wave/T saveName = $"root:myGlobals:CombineTable:SaveName" 
     
    18052281        endif 
    18062282 
    1807  
    1808         if( !(num==2 || num==3) ) 
    1809                 Abort "invalid table selection - must select either 2 or 3 files to combine" 
    1810         endif 
    1811         Make/O/T/N=(3) tmpLbl 
    1812         Make/O/N=(3) tmpSDD,tmpRun 
     2283        if( !(num==2 || num==3 || num==4) ) 
     2284                Abort "invalid table selection - must select either 2 or 3 or 4 files to combine" 
     2285        endif 
     2286        Make/O/T/N=(4) tmpLbl 
     2287        Make/O/N=(4) tmpSDD,tmpRun 
     2288         
     2289        //initialize with fake values in case 2 or 3 files are combined 
     2290        tmpLbl = "" 
     2291        tmpSDD = 0.01           //fake sdd in meters to always be the "highest" Q 
     2292        tmpRun = 0                      //pass a run number of zero to be later interpreted as "none" 
     2293         
     2294        //fill in the real values from the selection 
    18132295        for(ii=V_startRow;ii<=V_endRow;ii+=1) 
    18142296                tmpLbl[ii-V_startRow] = gLabels[ii] 
     
    18162298                tmpRun[ii-V_startRow] = gRunNumber[ii] 
    18172299        endfor 
    1818         if(num==2)      // then "highest" q run needs to be forced to zero 
    1819                 ii=2 
    1820                 tmpLbl[ii] = "" 
    1821                 tmpSDD[ii] = 0.01               //fake sdd in meters to always be the "highest" Q 
    1822                 tmpRun[ii] = 0                  //pass a run number of zero to be later interpreted as "none" 
    1823         endif 
     2300//      if(num==2)      // then "highest" q run needs to be forced to zero 
     2301//              ii=2 
     2302//              tmpLbl[ii] = "" 
     2303//              tmpSDD[ii] = 0.01               //fake sdd in meters to always be the "highest" Q 
     2304//              tmpRun[ii] = 0                  //pass a run number of zero to be later interpreted as "none" 
     2305//      endif 
    18242306        Sort tmpSDD, tmpSDD,tmpLbl,tmpRun 
    18252307         
     
    18272309         
    18282310        num=numpnts(low) 
    1829         InsertPoints num, 1, low,medium,high,prefix,SaveName 
    1830         low[num] = tmpRun[2] 
    1831         medium[num] = tmpRun[1] 
    1832         high[num] = tmpRun[0] 
     2311        InsertPoints num, 1, low,medium,high,highest,prefix,SaveName 
     2312        low[num] = tmpRun[3] 
     2313        medium[num] = tmpRun[2] 
     2314        high[num] = tmpRun[1] 
     2315        highest[num] = tmpRun[0] 
    18332316        prefix[num] = GetPrefixStrFromFile(filenames[ii]) 
    18342317        saveName[num] = saveStr  
     
    19052388                Make/O/N=0 $"root:myGlobals:CombineTable:MediumRun" 
    19062389                Make/O/N=0 $"root:myGlobals:CombineTable:HighRun" 
     2390                Make/O/N=0 $"root:myGlobals:CombineTable:HighestRun" 
    19072391                Make/O/T/N=0 $"root:myGlobals:CombineTable:Prefix" 
    19082392                Make/O/T/N=0 $"root:myGlobals:CombineTable:SaveName" 
     
    19112395         
    19122396        // make the second table 
    1913         AppendToTable/W=CombinePanel#RunNumbersToCombine LowRun,MediumRun,HighRun,Prefix,SaveName 
     2397        AppendToTable/W=CombinePanel#RunNumbersToCombine LowRun,MediumRun,HighRun,HighestRun,Prefix,SaveName 
    19142398         
    19152399        SetDataFolder root: 
    19162400End 
     2401 
     2402 
     2403 
     2404///////////////////////////////// 
     2405// currently unused 
     2406// 
     2407Proc MakeCombineTable_byName() 
     2408        NewDataFolder/O root:myGlobals:CombineTable                     //in case it doesn't exist yet 
     2409        Make/O/T/N=1 lowQfile,medQfile,hiQfile,saveName 
     2410        Edit/W=(330,148,973,360) lowQfile,medQfile,hiQfile,saveName 
     2411        ModifyTable format(Point)=1,width(lowQfile)=120,width(medQfile)=120,width(hiQfile)=120 
     2412        ModifyTable width(saveName)=120  
     2413End 
     2414 
     2415// 
     2416// currently unused 
     2417// 
     2418// Another beta procedure, to allow files to be combined quickly 
     2419// - make 4 waves (text) with the low, med, hi, and wave names 
     2420// (if there is no hiQ, then pass a wave with "" for all entries) 
     2421// - then pass the waves, and the save will work like in the DoCombineFiles 
     2422// 
     2423// - the named files must be there - there is no error checking 
     2424// - the NSORT panel must be open with the proper selections of beg,end and autoscale, etc. 
     2425// 
     2426// - could write a little proc to generate a table to fill in and a button to call this 
     2427// - and then think of quick ways to populate the table with file names (and minimize typos) 
     2428// 
     2429Function DoCombineFiles_byName(lowW,medW,hiW,saveW) 
     2430        Wave/T lowW,medW,hiW,saveW 
     2431                 
     2432        if(WinType("NSORT_Panel") == 0) 
     2433                DoAlert 0, "The SORT Panel must be open to combine the files" 
     2434                return(0) 
     2435        endif 
     2436         
     2437        // pop all of the menus to make sure that they are properly populated 
     2438        LowQPopMenuProc("",1,"") 
     2439        MedQPopMenuProc("",1,"") 
     2440        HighQPopMenuProc("",1,"") 
     2441         
     2442        Variable num=numpnts(lowW),ii 
     2443        String lowFile,medFile,hiFile 
     2444         
     2445        Pathinfo catPathName 
     2446        String path=S_Path 
     2447         
     2448////////        Make/O/D/N=(numpnts(lowW)) scale_4m 
     2449        NVAR scale12 = root:myGlobals:NSORT:gScale1_2 
     2450 
     2451         
     2452// this variable must exist and be set to 1 to be able to automatically name files 
     2453// and use the global saveNameStr that is passed in 
     2454// -- turn this off when done    
     2455        Variable/G root:myGlobals:CombineTable:useTable=1                
     2456 
     2457        ii=0 
     2458        do 
     2459                lowFile = lowW[ii] 
     2460                medFile = medW[ii] 
     2461                hiFile = hiW[ii] 
     2462                 
     2463                //Set3NSORTFiles(lowFile,medFile,hiFile,prefixStr)              //set the files and pop the NSORT popups 
     2464                //lowQ menu 
     2465                PopupMenu popup_1 win=NSORT_Panel,popmatch=lowFile 
     2466                 
     2467                // mediumQ menu 
     2468                if(strlen(medFile)!=0) 
     2469                        PopupMenu popup_2 win=NSORT_Panel,popmatch=medFile 
     2470                else 
     2471                        PopupMenu popup_2,win=NSORT_Panel,popmatch="none"       //set to "none" 
     2472                endif 
     2473         
     2474                //highQ (same pop list as medQ) 
     2475                if(strlen(hiFile)!=0) 
     2476                        PopupMenu popup_3 win=NSORT_Panel,popmatch=hiFile 
     2477                else 
     2478                        PopupMenu popup_3,win=NSORT_Panel,popmatch="none"       //set to "none" 
     2479                endif 
     2480                 
     2481                 
     2482                //pass the new file name in as a global (ugh!) 
     2483                String/G root:myGlobals:CombineTable:SaveNameStr = path+saveW[ii] 
     2484                //combine the files and write the data 
     2485                WriteNSORTFileButton("") 
     2486                 
     2487//////          scale_4m[ii] = scale12 
     2488                 
     2489                Print "wrote file : ",path+saveW[ii] 
     2490                ii+=1 
     2491        while(ii<num) 
     2492 
     2493        Variable/G root:myGlobals:CombineTable:useTable=0               //turn this off immediately 
     2494         
     2495        return(0) 
     2496End 
Note: See TracChangeset for help on using the changeset viewer.