Ignore:
Timestamp:
Mar 7, 2016 11:55:46 AM (7 years ago)
Author:
srkline
Message:

CHANGES to SANS:
Now allow 4 files to be combined in one step. This required modification of one routine in NIST_XML to allow an extra file name, and significant addition to the NSORT panel to allow an (optional) 4th data file. behaviors are still the same as before with 2, 3, or 4 sets being allowed. The "combine table" also allows up to 4 files to be combined (can be mixed, 2, 3, 4 all allowed).

More addtions to VSANS present as well, not specific changes, but in-progress changes to the beam center handling and ciombining data to 1D.

File:
1 edited

Legend:

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

    r902 r983  
    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) 
     
    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/W=NSORT_Panel 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 
    403427                        ControlInfo/W=NSORT_Panel popup_2 
    404                 else 
     428                        break 
     429                case "Plot_3":           
    405430                        //high-q 
    406431                        setNum = 3 
    407432                        ControlInfo/W=NSORT_Panel popup_3 
    408                 Endif 
    409         Endif 
    410          
     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 
     
    559626        MedQPopMenuProc("popup_2",1,"") 
    560627        HighQPopMenuProc("popup_3",1,"") 
     628        HighestQPopMenuProc("popup_4",1,"") 
    561629         
    562630End 
     
    572640// 2 == MedQ 
    573641// 3 == HighQ 
     642// 4 == HighestQ 
    574643// 
    575644//"Plot_1" is the low-q button name 
    576645//"Plot_2" is the med-q button name 
    577646//"Plot_3" is the high-q button name 
     647//"Plot_4" is the high-q button name 
    578648// 
    579649//calling plot_0_Button() responds as if that named button were pressed 
     
    610680        NVAR Columns2 = root:myGlobals:NSORT:gColumns2 
    611681        NVAR Columns3 = root:myGlobals:NSORT:gColumns3 
    612         if( (Columns1 == 3) || (Columns2 == 3) || (Columns3 == 3) )  
     682        NVAR Columns4 = root:myGlobals:NSORT:gColumns4 
     683        if( (Columns1 == 3) || (Columns2 == 3) || (Columns3 == 3) || (Columns4 == 3))  
    613684                isAThree = 1 
    614685        endif 
    615         if( (Columns1 == 6) || (Columns2 == 6) || (Columns3 == 6) )  
     686        if( (Columns1 == 6) || (Columns2 == 6) || (Columns3 == 6) || (Columns4 == 6))  
    616687                isASix = 1 
    617688        endif 
     
    621692         
    622693        //is there just one data set? if so, then dispatch to a simpler routine, since no normalization is needed 
    623         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 
    624695        fileStr = S_Value 
    625696        if(cmpstr(fileStr,"none") == 0) 
     
    658729                ControlInfo/W=NSORT_Panel popup_1 
    659730                if(isAThree) 
    660                         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) 
    661732                else 
    662                         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) 
    663734                endif 
    664735                //  just get the new list and return - don't actually "pop" the menu, or the selected item will change 
     
    692763Window NSORT_Panel() 
    693764        PauseUpdate; Silent 1           // building window... 
    694         NewPanel /W=(569,69,944,485)/K=2 
     765        NewPanel /W=(569,69,944,584)//K=2 
    695766        ModifyPanel cbRGB=(49151,53155,65535) 
    696767        ModifyPanel fixedSize=1 
     
    702773        DrawLine 0,214,346,214 
    703774        DrawLine 0,295,346,295 
     775        DrawLine 0,372,347,372 
     776        DrawLine 0,460,346,460 
     777         
    704778        SetDrawEnv fstyle= 5 
    705779        DrawText 5,74,"Low Q:" 
     
    708782        SetDrawEnv fstyle= 5 
    709783        DrawText 8,234,"High Q: (or none)" 
     784        SetDrawEnv fstyle= 5 
     785        DrawText 8,314,"Highest Q: (or none)" 
    710786        SetDrawEnv fstyle= 4 
    711787        DrawText 178,75,"Delete Points?" 
     
    714790        SetDrawEnv fstyle= 4 
    715791        DrawText 184,236,"Delete Points?" 
    716         DrawLine 0,363,346,363 
    717         DrawText 31,357,"To Manually scale data, enter scale factors above" 
    718         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" 
    719797        Button NSORT_Done,help={"closes the panel"} 
    720798        Button Plot_1,pos={279,63},size={50,20},proc=Plot_0_Button,title="Plot" 
     
    724802        Button Plot_3,pos={284,223},size={50,20},proc=Plot_0_Button,title="Plot" 
    725803        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 
    726807        Button PathButton,pos={6,26},size={80,20},proc=NSORTPickPathButton,title="Pick Path" 
    727808        Button PathButton,help={"Select the local path to the folder containing your SANS data"} 
     
    740821        SetVariable end_3,fSize=10,help={"How many points to remove from the high-q end of this dataset"} 
    741822        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 
    742827        SetVariable beg_1,pos={182,79},size={80,14},proc=SetBegOrEnd,title="Beg Pts" 
    743828        SetVariable beg_1,fSize=10,help={"How many points to remove from the low-q end of this dataset"} 
     
    749834        SetVariable beg_3,fSize=10,help={"How many points to remove from the low-q end of this dataset"} 
    750835        SetVariable beg_3,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gPtsBeg3 
    751         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" 
    752841        Button DoCombine,help={"Combine and normalize the selected files as specifed"} 
    753         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" 
    754843        SetVariable scale_12,fSize=10,help={"Factor that will multiply medium-q set to scale to low-q set"} 
    755844        SetVariable scale_12,limits={-Inf,Inf,0},value= root:myGlobals:NSORT:gScale1_2 
    756         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" 
    757846        SetVariable scale_23,fSize=10,help={"Factor that will multiply high-q set to scale to medium-q set"} 
    758847        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 
    759852        CheckBox check1,pos={5,105},size={160,20},proc=CheckProc,title="Normalize to this file",value=1 
    760853        CheckBox check1,help={"If checked, the combined dataset will be normalized to this dataset"} 
     
    763856        CheckBox check3,pos={4,270},size={160,20},proc=CheckProc,title="Normalize to this file",value=0 
    764857        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 
    765861        PopupMenu popup_1,pos={6,77},size={99,19},proc=LowQPopMenuProc 
    766862        PopupMenu popup_1,mode=1,value= #"root:myGlobals:NSORT:gDataPopList" 
     
    772868        PopupMenu popup_3,mode=1,value= #"root:myGlobals:NSORT:gDataPopList_3" 
    773869        PopupMenu popup_3,help={"Choose the dataset with the highest overall q-value (shortest detector distance), or NONE if no third set desired"} 
    774         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 
    775874        CheckBox AutoCheck,help={"If checked, the scale factor will be automatically determined, if not checked, the current values in the fields will be used"} 
    776         CheckBox PreviewCheck,pos={15,369},size={74,14},title="Preview Only",value= 0 
    777         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 
    778877EndMacro 
    779878 
     
    801900 
    802901        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 
    803914End 
    804915 
     
    821932                        CheckBox check2 value=1 
    822933                        CheckBox check3 value=0 
     934                        CheckBox check4 value=0 
    823935                        Variable/G root:myGlobals:NSORT:gNormToNum = 2 
    824936                        break 
     
    828940                        CheckBox check2 value=0 
    829941                        CheckBox check3 value=1 
     942                        CheckBox check4 value=0 
    830943                        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 
    831952                        break 
    832953                Endif 
     
    835956                CheckBox check2 value=0 
    836957                CheckBox check3 value=0 
     958                        CheckBox check4 value=0 
    837959                Variable/G root:myGlobals:NSORT:gNormToNum = 1 
    838960        While(0) 
     961         
    839962        ControlUpdate/A/W=NSORT_Panel 
    840                 DoUpdate 
     963        DoUpdate 
    841964                 
    842965End 
     
    8981021 
    8991022 
     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 
    9001051//be sure to use the "Trim.." datasets that have had the bad points removed 
    9011052//and then do the scaling based on the choices in the panel 
     
    9061057 
    9071058        NVAR normTo = root:myGlobals:NSORT:gNormToNum 
    908         Variable err=0,setNum,norm12,norm23 
    909         String fileStr="",tempName="",name1="",name2="",name3="",normToStr="" 
     1059        Variable err=0,setNum,norm12,norm23,norm34 
     1060        String fileStr="",tempName="",name1="",name2="",name3="",normToStr="",name4="" 
    9101061         
    9111062//Set the number of output columns 
     
    9151066        NVAR Columns2 = root:myGlobals:NSORT:gColumns2 
    9161067        NVAR Columns3 = root:myGlobals:NSORT:gColumns3 
    917         if( (Columns1 == 3) || (Columns2 == 3) || (Columns3 == 3) )  
     1068        NVAR Columns4 = root:myGlobals:NSORT:gColumns4 
     1069        if( (Columns1 == 3) || (Columns2 == 3) || (Columns3 == 3) || (Columns4 == 3) )  
    9181070                numOutputColumns = 3 
    9191071        else 
    920                 if( (Columns1 == 6) && (Columns2 == 6) && ((Columns3 == 0) || (Columns3 == 6)) )  
     1072                if( (Columns1 == 6) && (Columns2 == 6) && ((Columns3 == 0) || (Columns3 == 6)) || (Columns4 == 6) )  
    9211073                        numOutputColumns = 6 
    9221074                endif 
     
    9711123        //////end load file3 
    9721124         
     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         
    9731144        //assign filename of file to normalize to 
    974         if(normTo == 1) 
    975                 normToStr = name1 
    976         else 
    977                 if(normTo == 2) 
     1145        switch(normTo) 
     1146                case 1: 
     1147                        normToStr = name1 
     1148                        break 
     1149                case 2: 
    9781150                        normToStr = name2 
    979                 else 
     1151                        break 
     1152                case 3: 
    9801153                        normToStr = name3 
    981                 Endif 
    982         Endif 
     1154                        break 
     1155                case 4: 
     1156                        normToStr = name4 
     1157                        break 
     1158        endswitch 
     1159 
    9831160 
    9841161        Variable n1,n2,n12,num2 
    9851162        Variable n3,n123 
     1163        Variable n4,n1234 
    9861164         
    9871165   if(numOutputColumns == 3) //Start the 3-column specific stuff here. 
     
    10711249                        ControlInfo/W=NSORT_Panel PreviewCheck 
    10721250                        if( V_Value==0 )                //if zero skip the preview and write out the file 
    1073                                 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) 
    10741252                        endif 
    10751253                        //cleanup waves before exiting 
     
    11611339                ControlInfo/W=NSORT_Panel PreviewCheck 
    11621340                if( V_Value==0 )                //if zero skip the preview and write out the file 
    1163                         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) 
    11641342                endif 
    11651343                //cleanup waves before exiting 
    11661344                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                 
    11671462                //combined dataset will already be displayed if the NSORT_Graph is open 
    11681463         
     
    11881483                WAVE lows = $"root:LowQSet:TrimLowQSet_s" 
    11891484                WAVE meds = $"root:MedQSet:TrimMedQSet_s" 
    1190 //              WAVE lowsq = $"root:LowQSet:TrimLowQSet_sq" 
    1191 //              WAVE medsq = $"root:MedQSet:TrimMedQSet_sq" 
    1192 //              WAVE lowqb = $"root:LowQSet:TrimLowQSet_qb" 
    1193 //              WAVE medqb =  $"root:MedQSet:TrimMedQSet_qb" 
    1194 //              WAVE lowfs = $"root:LowQSet:TrimLowQSet_fs" 
    1195 //              WAVE medfs = $"root:MedQSet:TrimMedQSet_fs" 
    11961485                WAVE lowres = $"root:LowQSet:TrimLowQSet_res" 
    11971486                WAVE medres = $"root:MedQSet:TrimMedQSet_res" 
     
    12091498                fs12[0,n1-1] = lowres[p][2] 
    12101499                fs12[n1,n1+n2-1]= medres[p-n1][2] 
    1211 //              res12[0,n1-1][0]=lowres[p][0] 
    1212 //              res12[n1,n1+n2-1][0]=medres[p-n1][0] 
    1213 //              res12[0,n1-1][1]=lowres[p][1] 
    1214 //              res12[n1,n1+n2-1][1]=medres[p-n1][1] 
    1215 //              res12[0,n1-1][2]=lowres[p][2] 
    1216 //              res12[n1,n1+n2-1][2]=medres[p-n1][2] 
    12171500 
    12181501                 
     
    12731556                fs12[0,n1-1] = lowres[p][2] 
    12741557                fs12[n1,n1+n2-1]= medres[p-n1][2] 
    1275 //              res12[0,n1-1][0]=lowres[p][0] 
    1276 //              res12[n1,n1+n2-1][0]=medres[p-n1][0] 
    1277 //              res12[0,n1-1][1]=lowres[p][1] 
    1278 //              res12[n1,n1+n2-1][1]=medres[p-n1][1] 
    1279 //              res12[0,n1-1][2]=lowres[p][2] 
    1280 //              res12[n1,n1+n2-1][2]=medres[p-n1][2] 
    12811558 
    12821559                 
     
    12941571                                res12[][1] = qb12[p] 
    12951572                                res12[][2] = fs12[p] 
    1296                                 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) 
    12971574                        endif 
    12981575                        // always clean up waves before exiting 
     
    13161593                WAVE highi = $"root:HighQSet:TrimHighQSet_i" 
    13171594                WAVE highs = $"root:HighQSet:TrimHighQSet_s" 
    1318 //              WAVE highsq = $"root:HighQSet:TrimHighQSet_sq" 
    1319 //              WAVE highqb = $"root:HighQSet:TrimHighQSet_qb" 
    1320 //              WAVE highfs = $"root:HighQSet:TrimHighQSet_fs" 
    13211595                WAVE highres = $"root:HighQSet:TrimHighQSet_res" 
    13221596         
    13231597         
    13241598                q123[0,n12-1] = q12[p] 
    1325                 q123[n1,n12+n3-1]= highq[p-n12] 
     1599                q123[n12,n12+n3-1]= highq[p-n12] 
    13261600                i123[0,n12-1] = i12[p] 
    1327                 i123[n1,n12+n3-1]= highi[p-n12] 
     1601                i123[n12,n12+n3-1]= highi[p-n12] 
    13281602                sig123[0,n12-1] = sig12[p] 
    1329                 sig123[n1,n12+n3-1]= highs[p-n12] 
     1603                sig123[n12,n12+n3-1]= highs[p-n12] 
    13301604                sq123[0,n12-1] = sq12[p] 
    1331                 sq123[n1,n12+n3-1]= highres[p-n12][0] 
     1605                sq123[n12,n12+n3-1]= highres[p-n12][0] 
    13321606                qb123[0,n12-1] = qb12[p] 
    1333                 qb123[n1,n12+n3-1]= highres[p-n12][1] 
     1607                qb123[n12,n12+n3-1]= highres[p-n12][1] 
    13341608                fs123[0,n12-1] = fs12[p] 
    1335                 fs123[n1,n12+n3-1]= highres[p-n12][2] 
    1336 //              res123[0,n12-1][0] = highres[p][0] 
    1337 //              res123[n1,n12+n3-1][0] = highres[p-n12][0] 
    1338 //              res123[0,n12-1][1] = highres[p][1] 
    1339 //              res123[n1,n12+n3-1][1] = highres[p-n12][1] 
    1340 //              res123[0,n12-1][2] = highres[p][2] 
    1341 //              res123[n1,n12+n3-1][2] = highres[p-n12][2] 
     1609                fs123[n12,n12+n3-1]= highres[p-n12][2] 
    13421610 
    13431611                 
     
    14011669                fs123[0,n12-1] = fs12[p] 
    14021670                fs123[n12,n12+n3-1]= highres[p-n12][2] 
    1403 //              res123[0,n12-1][0] = highres[p][0] 
    1404 //              res123[n1,n12+n3-1][0] = highres[p-n12][0] 
    1405 //              res123[0,n12-1][1] = highres[p][1] 
    1406 //              res123[n1,n12+n3-1][1] = highres[p-n12][1] 
    1407 //              res123[0,n12-1][2] = highres[p][2] 
    1408 //              res123[n1,n12+n3-1][2] = highres[p-n12][2] 
     1671 
    14091672                 
    14101673                Sort q123, q123,i123,sig123,sq123,qb123,fs123 
    14111674                //at this point 12 - 3 are combined 
    1412                 //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 
    14131800         
    14141801                ControlInfo/W=NSORT_Panel PreviewCheck 
    14151802                if( V_Value==0 )                //if zero skip the preview and write out the file 
    1416                         res123[][0] = sq123[p] 
    1417                         res123[][1] = qb123[p] 
    1418                         res123[][2] = fs123[p] 
    1419                         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) 
    14201807                endif 
    1421                 //cleanup waves before exiting 
    1422                 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 
    14231812                //combined dataset will already be displayed if the NSORT_Graph is open 
    14241813         
    14251814                //////////////// 
    14261815                return err 
    1427    endif // End the 6-column specific stuff here 
    1428          
    1429 End 
     1816   endif // End the if(6-column) specific stuff here 
     1817         
     1818         
     1819End 
     1820 
     1821 
     1822 
    14301823 
    14311824 
     
    14881881                PopupMenu popup_3,win=NSORT_Panel,mode=(1) 
    14891882        endif 
     1883End 
     1884 
     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) 
    14901962End 
    14911963 
     
    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: 
     
    19192403 
    19202404///////////////////////////////// 
    1921  
     2405// currently unused 
     2406// 
    19222407Proc MakeCombineTable_byName() 
    19232408        NewDataFolder/O root:myGlobals:CombineTable                     //in case it doesn't exist yet 
     
    19282413End 
    19292414 
     2415// 
     2416// currently unused 
     2417// 
    19302418// Another beta procedure, to allow files to be combined quickly 
    19312419// - make 4 waves (text) with the low, med, hi, and wave names 
Note: See TracChangeset for help on using the changeset viewer.