Ignore:
Timestamp:
Nov 30, 2012 3:43:34 PM (10 years ago)
Author:
srkline
Message:

Lots of changes to the Event Mode reading/processing. Added panels to allow correction of the event data, and a panel to create custom bins.

Added conditional compile to look for the EventLoadWave? operation from the EventLoadWave? XOP. The XOP is likely to be distributed with releases 7.13e and higher, pending testing.

Updated the FilesToRemove? and the installer to look for the EventLoader? XOP and remove it if it's present when updating.

File:
1 edited

Legend:

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

    r877 r880  
    1212//     It's all a stream, just sometimes it's not oscillatory 
    1313// 
    14 // -- fix the log/lin display - it's not working correctly 
     14// X- fix the log/lin display - it's not working correctly 
    1515//                      I could use ModifyImage and log = 0|1 keyword for the log Z display 
    1616//                      rather than creating a duplicate wave of log(data) 
    1717//                      -- it's in the Function sliceSelectEvent_Proc() 
    1818// 
    19 // -- Do something withe the PP events. Currently, nothing is done (since I still need 
    20 //     to find out what they realy mean) 
     19// -- the slice display "fails" for data sets that have 3 or 4 slices, as the ModifyImage command 
     20//     interprets the data as being RGB - and so does nothing. 
     21//     need to find a way around this 
     22// 
     23// -- Do something with the PP events. Currently, only the PP events that are XY (just the 
     24//    type 0 events (since I still need to find out what they realy mean) 
    2125// 
    2226// -- Add a switch to allow Sorting of the Stream data to remove the "time-reversed" data 
     
    2933//     rather that Igor handles the memory management, not me, if I write the XOP. 
    3034// 
     35// **- as of 11/27, the OSX version of the XOP event loader is about 35x faster for the load! 
     36//    and is taking approx 1.8s/28MB, or about 6.5s/100MB of file. quite reasonable now, and 
     37//    probably a bit faster yet on the PC. 
     38// 
     39// -- memory issues: 
     40//              -- in LoadEvents -- should I change the MAKE to: 
     41//                              /I/U is unsigned 32-bit integer (for the time) 
     42//                              /B/U is unsigned 8-bit integer (max val=255) for the x and y values 
     43//                      -- then how does this affect downstream processing - such as rescaledTime, differentiation, etc. 
     44//                      x- and can I re-write the XOP to create these types of data waves, and properly fill them... 
     45// 
     46//  **- any integer waves must be translated by Igor into FP to be able to be displayed or for any 
     47//    type of analysis. so it's largely a waste of time to use integers. so simply force the XOP to  
     48//    generate only SP waves. this will at least save some space. 
     49// 
    3150// X- add controls to show the bar graph 
    3251// x- add popup for selecting the binning type 
     
    3958//     size, then a second time to actualy process the events. Would it be faster to insert points 
    4059//     as needed, or to estimate the size, and make it too large, then trim at the end... 
    41 // ((( NO -- deleting the extra zeros at the end is WAY WAY slower - turns 2sec into 100 sec))) 
     60// ((( NO -- I have no good way of getting a proper estimate of how many XY events there are for a file)) 
    4261// 
    4362// 
     
    94113        Variable/G root:Packages:NIST:gSortStreamEvents = 0             // ==1 to sort the event stream, a last resort for a stream of data 
    95114         
     115        Variable/G root:Packages:NIST:gEvent_ForceTmaxBin=1             //==1 to enforce t_longest in user-defined custom bins 
     116 
    96117        NVAR nslices = root:Packages:NIST:gEvent_nslices 
    97118         
     
    143164         
    144165//      PopupMenu popup0 title="Bin Spacing",pos={150,90},value="Equal;Fibonacci;Log;" 
    145         PopupMenu popup0 title="Bin Spacing",pos={150,90},value="Equal;Fibonacci;" 
     166        PopupMenu popup0 title="Bin Spacing",pos={150,90},value="Equal;Fibonacci;Custom;" 
     167        PopupMenu popup0 proc=BinTypePopMenuProc 
    146168         
    147169        CheckBox chkbox2,pos={20,95},title="Log Intensity",value=1 
     
    185207End 
    186208 
     209Function BinTypePopMenuProc(pa) : PopupMenuControl 
     210        STRUCT WMPopupAction &pa 
     211 
     212        switch( pa.eventCode ) 
     213                case 2: // mouse up 
     214                        Variable popNum = pa.popNum 
     215                        String popStr = pa.popStr 
     216                        if(cmpstr(popStr,"Custom")==0) 
     217                                Execute "Show_CustomBinPanel()" 
     218                        endif 
     219                        break 
     220                case -1: // control being killed 
     221                        break 
     222        endswitch 
     223 
     224        return 0 
     225End 
     226 
    187227Function ShowBinDetailsButtonProc(ba) : ButtonControl 
    188228        STRUCT WMButtonAction &ba 
     
    274314        endif 
    275315         
     316        // toggle the checkbox for log display to force the display to be correct 
     317        NVAR gLog = root:Packages:NIST:gEvent_logint 
     318        LogIntEvent_Proc("",gLog) 
    276319         
    277320        return(0) 
     
    304347        Make/O/D/N=(128,128) tmpData 
    305348        Make/O/D/N=(nslices+1) binEndTime,binCount 
     349        Make/O/D/N=(nslices) timeWidth 
     350        Wave timeWidth = timeWidth 
    306351        Wave binEndTime = binEndTime 
    307352        Wave binCount = binCount 
     
    321366        strswitch(binTypeStr)   // string switch 
    322367                case "Equal":           // execute if case matches expression 
    323                         SetLinearBins(binEndTime,nslices,t_longest) 
     368                        SetLinearBins(binEndTime,timeWidth,nslices,t_longest) 
    324369                        break                                           // exit from switch 
    325370                case "Fibonacci":               // execute if case matches expression 
    326                         SetFibonacciBins(binEndTime,nslices,t_longest) 
     371                        SetFibonacciBins(binEndTime,timeWidth,nslices,t_longest) 
    327372                        break 
    328373                case "Log":             // execute if case matches expression 
    329                         SetLogBins(binEndTime,nslices,t_longest) 
     374                        SetLogBins(binEndTime,timeWidth,nslices,t_longest) 
    330375                        break 
    331376                default:                                                        // optional default expression executed 
    332377                        DoAlert 0,"No match for bin type, Equal bins used" 
    333                         SetLinearBins(binEndTime,nslices,t_longest) 
     378                        SetLinearBins(binEndTime,timeWidth,nslices,t_longest) 
    334379        endswitch 
    335380 
     
    376421                        p2 = numpnts(rescaledTime)-1            //set to the last point if it's off the end 
    377422                Endif 
    378                 Print p1,p2 
     423//              Print p1,p2 
    379424 
    380425 
     
    428473        Make/O/D/N=(128,128) tmpData 
    429474        Make/O/D/N=(nslices+1) binEndTime,binCount//,binStartTime 
     475        Make/O/D/N=(nslices) timeWidth 
    430476        Wave binEndTime = binEndTime 
    431 //      Wave binStartTime = binStartTime 
     477        Wave timeWidth = timeWidth 
    432478        Wave binCount = binCount 
    433479 
     
    445491        strswitch(binTypeStr)   // string switch 
    446492                case "Equal":           // execute if case matches expression 
    447                         SetLinearBins(binEndTime,nslices,t_longest) 
     493                        SetLinearBins(binEndTime,timeWidth,nslices,t_longest) 
    448494                        break                                           // exit from switch 
    449495                case "Fibonacci":               // execute if case matches expression 
    450                         SetFibonacciBins(binEndTime,nslices,t_longest) 
     496                        SetFibonacciBins(binEndTime,timeWidth,nslices,t_longest) 
    451497                        break 
    452498                case "Log":             // execute if case matches expression 
    453                         SetLogBins(binEndTime,nslices,t_longest) 
     499                        SetLogBins(binEndTime,timeWidth,nslices,t_longest) 
     500                        break 
     501                case "Custom":          // execute if case matches expression 
     502                        //SetLogBins(binEndTime,nslices,t_longest) 
    454503                        break 
    455504                default:                                                        // optional default expression executed 
    456505                        DoAlert 0,"No match for bin type, Equal bins used" 
    457                         SetLinearBins(binEndTime,nslices,t_longest) 
     506                        SetLinearBins(binEndTime,timeWidth,nslices,t_longest) 
    458507        endswitch 
    459508 
     
    489538                        p2 = numpnts(rescaledTime)-1            //set to the last point if it's off the end 
    490539                Endif 
    491                 Print p1,p2 
     540//              Print p1,p2 
    492541 
    493542 
     
    561610 
    562611 
    563 Function SetLinearBins(binEndTime,nslices,t_longest) 
    564         Wave binEndTime 
     612Function SetLinearBins(binEndTime,timeWidth,nslices,t_longest) 
     613        Wave binEndTime,timeWidth 
    565614        Variable nslices,t_longest 
    566615 
     
    575624        binEndTime[ii+1] = t_longest*(1-1e-6)           //otherwise floating point errors such that the last time point is off the end of the Binary search 
    576625 
     626        timeWidth = binEndTime[p+1]-binEndTime[p] 
     627 
    577628        return(0)        
    578629End 
    579630 
    580631 
    581 Function SetLogBins(binEndTime,nslices,t_longest) 
    582         Wave binEndTime 
     632Function SetLogBins(binEndTime,timeWidth,nslices,t_longest) 
     633        Wave binEndTime,timeWidth 
    583634        Variable nslices,t_longest 
    584635 
     
    597648        binEndTime[ii+1] = t_longest            //otherwise floating point errors such that the last time point is off the end of the Binary search 
    598649         
     650        timeWidth = binEndTime[p+1]-binEndTime[p] 
     651 
    599652        return(0) 
    600653End 
     
    619672end 
    620673 
    621 Function SetFibonacciBins(binEndTime,nslices,t_longest) 
    622         Wave binEndTime 
     674Function SetFibonacciBins(binEndTime,timeWidth,nslices,t_longest) 
     675        Wave binEndTime,timeWidth 
    623676        Variable nslices,t_longest 
    624677 
     
    640693        binEndTime[ii+1] = t_longest            //otherwise floating point errors such that the last time point is off the end of the Binary search 
    641694         
     695        timeWidth = binEndTime[p+1]-binEndTime[p] 
     696         
    642697        return(0) 
    643698End 
     
    650705 
    651706        NVAR mode=root:Packages:NIST:gEvent_mode 
     707        Variable err=0 
    652708         
    653709        if(mode == 0) 
    654                 Stream_LoadEventLog("") 
     710                err = Stream_LoadEventLog("") 
     711                if(err == 1) 
     712                        return(0)               // user cancelled from file load 
     713                endif 
    655714        endif 
    656715         
    657716        if(mode == 1) 
    658                 Osc_LoadEventLog("") 
     717                err = Osc_LoadEventLog("") 
     718                if(err == 1) 
     719                        return(0)               // user cancelled from file load 
     720                endif 
    659721        endif 
    660722 
     
    681743        Open/R/D/F=fileFilters fileref 
    682744        filename = S_filename 
     745        if(strlen(S_filename) == 0) 
     746                // user cancelled 
     747                DoAlert 0,"No file selected, no file loaded." 
     748                return(1) 
     749        endif 
     750 
     751#if (exists("EventLoadWave")==4) 
     752 
     753        LoadEvents_XOP() 
     754 
     755#else 
    683756         
    684757        LoadEvents() 
    685          
     758 
     759#endif   
     760 
    686761        SetDataFolder root:Packages:NIST:Event: 
    687762 
     
    718793        Open/R/D/F=fileFilters fileref 
    719794        filename = S_filename 
     795                if(strlen(S_filename) == 0) 
     796                // user cancelled 
     797                DoAlert 0,"No file selected, no file loaded." 
     798                return(1) 
     799        endif 
     800         
     801#if (exists("EventLoadWave")==4) 
     802 
     803        LoadEvents_XOP() 
     804 
     805#else 
    720806         
    721807        LoadEvents() 
     808 
     809#endif   
    722810         
    723811        SetDataFolder root:Packages:NIST:Event: 
     
    740828 
    741829 
    742  
     830// 
     831// -- MUCH faster to count the number of lines to remove, then delete (N) 
     832// rather then delete them one-by-one in the do-loop 
    743833Function CleanupTimes(xLoc,yLoc,timePt) 
    744834        Wave xLoc,yLoc,timePt 
    745835 
    746836        // start at the back and remove zeros 
    747         Variable num=numpnts(xLoc),ii 
    748          
     837        Variable num=numpnts(xLoc),ii,numToRemove 
     838 
     839        numToRemove = 0 
    749840        ii=num 
    750841        do 
    751842                ii -= 1 
    752843                if(timePt[ii] == 0 && xLoc[ii] == 0 && yLoc[ii] == 0) 
    753                         DeletePoints ii, 1, xLoc,yLoc,timePt 
     844                        numToRemove += 1 
    754845                endif 
    755846        while(timePt[ii-1] == 0 && xLoc[ii-1] == 0 && yLoc[ii-1] == 0) 
     847         
     848        if(numToRemove != 0) 
     849                DeletePoints ii, numToRemove, xLoc,yLoc,timePt 
     850        endif 
    756851         
    757852        return(0) 
     
    769864        endif 
    770865 
     866        NVAR selectedslice = root:Packages:NIST:gEvent_tsdisp 
     867 
     868        sliceSelectEvent_Proc("", selectedslice, "", "") 
     869 
    771870        SetDataFolder root: 
     871 
    772872End 
    773873 
     
    805905 
    806906        Wave rescaledTime = root:Packages:NIST:Event:rescaledTime 
    807          
     907 
     908        SetDataFolder root:Packages:NIST:Event: 
     909                 
    808910        Differentiate rescaledTime/D=rescaledTime_DIF 
    809911//      Display rescaledTime,rescaledTime_DIF 
     
    817919                Label bottom "\\Z14Event number" 
    818920        endif 
     921         
     922        SetDataFolder root: 
    819923         
    820924        return(0) 
     
    9391043        Close fileref 
    9401044//              done counting the number of XY events 
     1045        printf("Igor pre-scan done in  ") 
    9411046        toc() 
    942  
    943 Print "numT0 = ",numT0   
     1047         
     1048 
     1049Print "(Igor) numT0 = ",numT0    
     1050Print "num0 = ",num0     
     1051Print "num1 = ",num1     
     1052Print "num2 = ",num2     
     1053Print "num3 = ",num3     
    9441054         
    9451055// 
     
    9741084        dispStr += tmpStr 
    9751085 
    976          
     1086        // /I/U is unsigned 32-bit integer (for the time) 
     1087        // /B/U is unsigned 8-bit integer (max val=255) for the x and y values 
    9771088         
    9781089        Make/O/U/N=(numXYevents) xLoc,yLoc 
     
    10871198                                if(dataval == 0 && RemoveBadEvents == 1) 
    10881199                                        numRemoved += 1 
     1200                                        //Print "zero at ii= ",ii 
    10891201                                        break           //don't increment ii 
    10901202                                endif 
     
    12681380        while(1) 
    12691381         
    1270          
    12711382        Close fileref 
    12721383         
     1384        printf("Igor full file read done in  ")  
    12731385        toc() 
    12741386         
    1275         Print "Events removed = ",numRemoved 
    1276          
    1277         sPrintf tmpStr,"\rBad Events = numBad = %d (%g %% of events)",numBad,numBad/numXYevents*100 
     1387        Print "Events removed (Igor) = ",numRemoved 
     1388         
     1389        sPrintf tmpStr,"\rBad Rollover Events = %d (%g %% of events)",numBad,numBad/numXYevents*100 
    12781390        dispStr += tmpStr 
    1279  
     1391        sPrintf tmpStr,"\rTotal Events Removed = %d (%g %% of events)",numRemoved,numRemoved/numXYevents*100 
     1392        dispStr += tmpStr 
    12801393        SetDataFolder root: 
    12811394         
     
    12841397End  
    12851398 
    1286 /// 
     1399////////////// 
     1400// 
     1401// This calls the XOP, as an operation 
     1402// 
     1403// 
     1404Function LoadEvents_XOP() 
     1405         
     1406//      NVAR time_msw = root:Packages:NIST:gEvent_time_msw 
     1407//      NVAR time_lsw = root:Packages:NIST:gEvent_time_lsw 
     1408        NVAR t_longest = root:Packages:NIST:gEvent_t_longest 
     1409         
     1410        SVAR filepathstr = root:Packages:NIST:gEvent_logfile 
     1411        SVAR dispStr = root:Packages:NIST:gEventDisplayString 
     1412         
     1413        SetDataFolder root:Packages:NIST:Event 
     1414 
     1415        Variable fileref 
     1416        String buffer 
     1417        String fileStr,tmpStr 
     1418        Variable dataval,timeval,type,numLines,verbose,verbose3 
     1419        Variable xval,yval,rollBit,nRoll,roll_time,bit29,bit28,bit27 
     1420        Variable ii,flaggedEvent,rolloverHappened,numBad=0,tmpPP=0,tmpT0=0 
     1421        Variable Xmax, yMax 
     1422         
     1423        xMax = 127              // number the detector from 0->127  
     1424        yMax = 127 
     1425         
     1426        numLines = 0 
     1427 
     1428         
     1429        // what I really need is the number of XY events 
     1430        Variable numXYevents,num1,num2,num3,num0,totBytes,numPP,numT0,numDL,numFF,numZero 
     1431        Variable numRemoved 
     1432        numXYevents = 0 
     1433        num0 = 0 
     1434        num1 = 0 
     1435        num2 = 0 
     1436        num3 = 0 
     1437        numPP = 0 
     1438        numT0 = 0 
     1439        numDL = 0 
     1440        numFF = 0 
     1441        numZero = 0 
     1442        numRemoved = 0 
     1443 
     1444// get the total number of bytes in the file 
     1445        Open/R fileref as filepathstr 
     1446                FStatus fileref 
     1447        Close fileref 
     1448 
     1449        totBytes = V_logEOF 
     1450        Print "total bytes = ", totBytes 
     1451         
     1452// 
     1453 
     1454//// 
     1455// 
     1456//  use the XOP operation to load in the data 
     1457// -- this does everything - the pre-scan and creating the waves 
     1458// 
     1459// need to zero the waves before loading, just in case 
     1460// 
     1461 
     1462        NVAR removeBadEvents = root:Packages:NIST:gRemoveBadEvents 
     1463 
     1464tic() 
     1465 
     1466//      Wave/Z wave0=wave0 
     1467//      Wave/Z wave1=wave1 
     1468//      Wave/Z wave2=wave2 
     1469// 
     1470//      if(WaveExists(wave0)) 
     1471//              MultiThread wave0=0 
     1472//      endif 
     1473//      if(WaveExists(wave1)) 
     1474//              MultiThread wave1=0 
     1475//      endif 
     1476//      if(WaveExists(wave2)) 
     1477//              MultiThread wave2=0 
     1478//      endif 
     1479 
     1480#if (exists("EventLoadWave")==4) 
     1481        if(removeBadEvents) 
     1482                EventLoadWave/R/N=EventWave filepathstr 
     1483        else 
     1484                EventLoadWave/N=EventWave  filepathstr 
     1485        endif 
     1486 
     1487#endif 
     1488 
     1489        Print "XOP files loaded = ",S_waveNames 
     1490 
     1491////            -- copy the waves over to xLoc,yLoc,timePt 
     1492        Wave/Z EventWave0=EventWave0 
     1493        Wave/Z EventWave1=EventWave1 
     1494        Wave/Z EventWave2=EventWave2 
     1495         
     1496         
     1497        Duplicate/O EventWave0,xLoc 
     1498        KillWaves/Z EventWave0 
     1499 
     1500        Duplicate/O EventWave1,yLoc 
     1501        KillWaves/Z EventWave1 
     1502 
     1503        Duplicate/O EventWave2,timePt 
     1504        KillWaves/Z EventWave2 
     1505 
     1506// could do this, but rescaled time will neeed to be converted to SP (or DP) 
     1507// and Igor loader was written with Make generating SP/DP waves 
     1508        // /I/U is unsigned 32-bit integer (for the time) 
     1509        // /B/U is unsigned 8-bit integer (max val=255) for the x and y values 
     1510         
     1511//      Redimension/B/U xLoc,yLoc 
     1512//      Redimension/I/U timePt 
     1513 
     1514        // access the variables from the XOP 
     1515        numT0 = V_numT0 
     1516        numPP = V_numPP 
     1517        num0 = V_num0 
     1518        num1 = V_num1 
     1519        num2 = V_num2 
     1520        num3 = V_num3 
     1521        numXYevents = V_nXYevents 
     1522        numZero = V_numZero 
     1523        numBad = V_numBad 
     1524        numRemoved = V_numRemoved 
     1525         
     1526        Print "(XOP) numT0 = ",numT0     
     1527        Print "num0 = ",num0     
     1528        Print "num1 = ",num1     
     1529        Print "num2 = ",num2     
     1530        Print "num3 = ",num3     
     1531         
     1532 
     1533// dispStr will be displayed on the panel 
     1534        fileStr = ParseFilePath(0, filepathstr, ":", 1, 0) 
     1535         
     1536        sprintf tmpStr, "%s: %d total bytes\r",fileStr,totBytes  
     1537        dispStr = tmpStr 
     1538        sprintf tmpStr,"numXYevents = %d\r",numXYevents 
     1539        dispStr += tmpStr 
     1540//      sprintf tmpStr,"XY = num0 = %d\r",num0 
     1541//      dispStr += tmpStr 
     1542//      sprintf tmpStr,"\rXY time = num2 = %d\rtime MSW = num1 = %d",num2,num1 
     1543//      dispStr += tmpStr 
     1544//      sprintf tmpStr,"XY time = num2 = %d\r",num2 
     1545//      dispStr += tmpStr 
     1546//      sprintf tmpStr,"time MSW = num1 = %d\r",num1 
     1547//      dispStr += tmpStr 
     1548        sprintf tmpStr,"PP = %d  :  ",numPP 
     1549        dispStr += tmpStr 
     1550        sprintf tmpStr,"ZeroData = %d\r",numZero 
     1551        dispStr += tmpStr 
     1552        sprintf tmpStr,"Rollover = %d",num3 
     1553        dispStr += tmpStr 
     1554 
     1555        toc() 
     1556         
     1557        Print "Events removed (XOP) = ",numRemoved 
     1558         
     1559        sPrintf tmpStr,"\rBad Rollover Events = %d (%g %% of events)",numBad,numBad/numXYevents*100 
     1560        dispStr += tmpStr 
     1561        sPrintf tmpStr,"\rTotal Events Removed = %d (%g %% of events)",numRemoved,numRemoved/numXYevents*100 
     1562        dispStr += tmpStr 
     1563 
     1564        SetDataFolder root: 
     1565         
     1566        return(0) 
     1567         
     1568End  
     1569 
     1570////////////// 
    12871571 
    12881572Proc BinEventBarGraph() 
     
    13071591        //      ModifyGraph log=1 
    13081592                ModifyGraph standoff=0 
     1593                SetAxis left 0,* 
    13091594                Label bottom "\\Z14Time (seconds)" 
    13101595                Label left "\\Z14Number of Events" 
     
    13221607                String fldrSav0= GetDataFolder(1) 
    13231608                SetDataFolder root:Packages:NIST:Event: 
    1324                 Edit/W=(498,699,1003,955) /K=1/N=BinEventTable binCount,binEndTime 
    1325                 ModifyTable format(Point)=1,sigDigits(binEndTime)=16,width(binEndTime)=218 
     1609                Edit/W=(498,699,1003,955) /K=1/N=BinEventTable binCount,binEndTime,timeWidth 
     1610                ModifyTable format(Point)=1,sigDigits(binEndTime)=8,width(binEndTime)=100 
    13261611                SetDataFolder fldrSav0 
    13271612        endif 
     
    13431628                ModifyGraph marker=19 
    13441629                ModifyGraph rgb(rescaledTime)=(0,0,0) 
    1345                 ModifyGraph msize=2 
     1630                ModifyGraph msize=1 
    13461631//              SetAxis/A=2 left                        //only autoscale the visible data (based on the bottom limits) 
    13471632//              SetAxis bottom 0,1500 
     
    16131898// 
    16141899//////////////// 
     1900 
     1901 
     1902////////////// Post-processing of the event mode data 
     1903 
     1904Macro EventCorrectionPanel() 
     1905 
     1906        PauseUpdate; Silent 1           // building window... 
     1907        SetDataFolder root:Packages:NIST:Event: 
     1908         
     1909        Display /W=(35,44,761,533)/K=2 rescaledTime 
     1910        DoWindow/C EventCorrectionPanel 
     1911        ModifyGraph mode=4 
     1912        ModifyGraph marker=19 
     1913        ModifyGraph rgb=(0,0,0) 
     1914        ModifyGraph msize=1 
     1915        ErrorBars rescaledTime OFF  
     1916        Label left "\\Z14Time (seconds)" 
     1917        Label bottom "\\Z14Event number"         
     1918        SetAxis bottom 0,0.10*numpnts(rescaledTime)             //show 1st 10% of data for speed in displaying 
     1919         
     1920        ControlBar 100 
     1921        Button button0,pos={18,12},size={70,20},proc=EC_AddCursorButtonProc,title="Cursors" 
     1922        Button button1,pos={153,11},size={80,20},proc=EC_AddTimeButtonProc,title="Add time" 
     1923        Button button2,pos={153,37},size={80,20},proc=EC_SubtractTimeButtonProc,title="Subtr time" 
     1924        Button button3,pos={153,64},size={90,20},proc=EC_TrimPointsButtonProc,title="Trim points" 
     1925        Button button4,pos={295,12},size={90,20},proc=EC_SaveWavesButtonProc,title="Save Waves" 
     1926        Button button5,pos={294,38},size={100,20},proc=EC_ImportWavesButtonProc,title="Import Waves" 
     1927        Button button6,pos={18,39},size={80,20},proc=EC_ShowAllButtonProc,title="All Data" 
     1928        Button button7,pos={683,9},size={30,20},proc=EC_HelpButtonProc,title="?" 
     1929        Button button8,pos={658,72},size={60,20},proc=EC_DoneButtonProc,title="Done" 
     1930         
     1931        SetDataFolder root: 
     1932         
     1933EndMacro 
     1934 
     1935Function EC_AddCursorButtonProc(ba) : ButtonControl 
     1936        STRUCT WMButtonAction &ba 
     1937 
     1938        switch( ba.eventCode ) 
     1939                case 2: // mouse up 
     1940                        // click code here 
     1941                        SetDataFolder root:Packages:NIST:Event: 
     1942                         
     1943                        Wave rescaledTime = rescaledTime 
     1944                        Cursor/P A rescaledTime 0 
     1945                        Cursor/P B rescaledTime numpnts(rescaledTime)-1 
     1946                        ShowInfo 
     1947                        SetDataFolder root: 
     1948                        break 
     1949                case -1: // control being killed 
     1950                        break 
     1951        endswitch 
     1952 
     1953        return 0 
     1954End 
     1955 
     1956Function EC_AddTimeButtonProc(ba) : ButtonControl 
     1957        STRUCT WMButtonAction &ba 
     1958 
     1959        switch( ba.eventCode ) 
     1960                case 2: // mouse up 
     1961                        // click code here 
     1962                        SetDataFolder root:Packages:NIST:Event: 
     1963                         
     1964                        Wave rescaledTime = rescaledTime 
     1965                        Wave timePt = timePt 
     1966                        Variable rollTime,rollTicks,ptA,ptB,lo,hi 
     1967                         
     1968                        rollTicks = 2^26                                // in ticks 
     1969                        rollTime = 2^26*1e-7            // in seconds 
     1970                        ptA = pcsr(A) 
     1971                        ptB = pcsr(B) 
     1972                        lo=min(ptA,ptB) 
     1973                        hi=max(ptA,ptB) 
     1974 
     1975                        MultiThread timePt[lo,hi] += rollTicks 
     1976                        MultiThread rescaledTime[lo,hi] += rollTime 
     1977 
     1978                         
     1979                        SetDataFolder root: 
     1980                        break 
     1981                case -1: // control being killed 
     1982                        break 
     1983        endswitch 
     1984 
     1985        return 0 
     1986End 
     1987 
     1988Function EC_SubtractTimeButtonProc(ba) : ButtonControl 
     1989        STRUCT WMButtonAction &ba 
     1990 
     1991        switch( ba.eventCode ) 
     1992                case 2: // mouse up 
     1993                        // click code here 
     1994                        SetDataFolder root:Packages:NIST:Event: 
     1995                         
     1996                        Wave rescaledTime = rescaledTime 
     1997                        Wave timePt = timePt 
     1998                        Variable rollTime,rollTicks,ptA,ptB,lo,hi 
     1999                         
     2000                        rollTicks = 2^26                                // in ticks 
     2001                        rollTime = 2^26*1e-7            // in seconds 
     2002                        ptA = pcsr(A) 
     2003                        ptB = pcsr(B) 
     2004                        lo=min(ptA,ptB) 
     2005                        hi=max(ptA,ptB) 
     2006                         
     2007                        MultiThread timePt[lo,hi] -= rollTicks 
     2008                        MultiThread rescaledTime[lo,hi] -= rollTime 
     2009 
     2010                        SetDataFolder root: 
     2011                         
     2012                        break 
     2013                case -1: // control being killed 
     2014                        break 
     2015        endswitch 
     2016 
     2017        return 0 
     2018End 
     2019 
     2020// points removed are inclusive 
     2021// 
     2022// put both cursors on the same point to remove just that single point 
     2023// 
     2024Function EC_TrimPointsButtonProc(ba) : ButtonControl 
     2025        STRUCT WMButtonAction &ba 
     2026 
     2027        switch( ba.eventCode ) 
     2028                case 2: // mouse up 
     2029                        // click code here 
     2030                        SetDataFolder root:Packages:NIST:Event: 
     2031                         
     2032                        Wave rescaledTime = rescaledTime 
     2033                        Wave timePt = timePt 
     2034                        Wave xLoc = xLoc 
     2035                        Wave yLoc = yLoc 
     2036                        Variable rollTime,ptA,ptB,numElements,lo,hi 
     2037                         
     2038                        rollTime = 2^26*1e-7            // in seconds 
     2039                        ptA = pcsr(A) 
     2040                        ptB = pcsr(B) 
     2041                        lo=min(ptA,ptB) 
     2042                        hi=max(ptA,ptB)                  
     2043                        numElements = abs(ptA-ptB)+1                    //so points removed are inclusive 
     2044                        DeletePoints lo, numElements, rescaledTime,timePt,xLoc,yLoc 
     2045                         
     2046                        printf "Points %g to %g have been deleted in rescaledTime, timePt, xLoc, and yLoc\r",ptA,ptB 
     2047                        SetDataFolder root: 
     2048                         
     2049                        break 
     2050                case -1: // control being killed 
     2051                        break 
     2052        endswitch 
     2053 
     2054        return 0 
     2055End 
     2056 
     2057// un-sort the data first, then save it 
     2058Function EC_SaveWavesButtonProc(ba) : ButtonControl 
     2059        STRUCT WMButtonAction &ba 
     2060 
     2061        switch( ba.eventCode ) 
     2062                case 2: // mouse up 
     2063                        // click code here 
     2064                         
     2065//                      Execute "UndoTheSorting()" 
     2066                         
     2067                        SetDataFolder root:Packages:NIST:Event: 
     2068                         
     2069                        Wave rescaledTime = rescaledTime 
     2070                        Wave timePt = timePt 
     2071                        Wave xLoc = xLoc 
     2072                        Wave yLoc = yLoc 
     2073                        Save/T xLoc,yLoc,timePt                 //will ask for a name 
     2074                         
     2075                        SetDataFolder root: 
     2076                        break 
     2077                case -1: // control being killed 
     2078                        break 
     2079        endswitch 
     2080 
     2081        return 0 
     2082End 
     2083 
     2084// this duplicates all of the bits that would be done if the "load" button was pressed 
     2085// 
     2086// 
     2087Function EC_ImportWavesButtonProc(ba) : ButtonControl 
     2088        STRUCT WMButtonAction &ba 
     2089 
     2090        switch( ba.eventCode ) 
     2091                case 2: // mouse up 
     2092                        // click code here 
     2093                        SetDataFolder root:Packages:NIST:Event: 
     2094 
     2095                        //SVAR filename = root:Packages:NIST:gEvent_logfile 
     2096                        //NVAR nslices = root:Packages:NIST:gEvent_nslices 
     2097                        NVAR t_longest = root:Packages:NIST:gEvent_t_longest 
     2098                        SVAR dispStr = root:Packages:NIST:gEventDisplayString 
     2099                        String tmpStr="",fileStr,filePathStr 
     2100                         
     2101                        // load in the waves, saved as Igor text to preserve the data type 
     2102                        LoadWave/T/O 
     2103                        filePathStr = S_fileName 
     2104                        if(strlen(S_fileName) == 0) 
     2105                                //user cancelled 
     2106                                DoAlert 0,"No file selected, nothing done." 
     2107                                return(0) 
     2108                        endif 
     2109                         
     2110                         
     2111                        Wave timePt=timePt 
     2112 
     2113                        Duplicate/O timePt rescaledTime 
     2114                        rescaledTime = 1e-7*(timePt-timePt[0])          //convert to seconds and start from zero 
     2115                        t_longest = waveMax(rescaledTime)               //should be the last point 
     2116         
     2117                        fileStr = ParseFilePath(0, filepathstr, ":", 1, 0) 
     2118                        sprintf tmpStr, "%s: a user-modified event file\r",fileStr  
     2119                        dispStr = tmpStr 
     2120         
     2121                        break 
     2122                case -1: // control being killed 
     2123                        break 
     2124        endswitch 
     2125 
     2126        return 0 
     2127End 
     2128 
     2129 
     2130Function EC_ShowAllButtonProc(ba) : ButtonControl 
     2131        STRUCT WMButtonAction &ba 
     2132 
     2133        switch( ba.eventCode ) 
     2134                case 2: // mouse up 
     2135                        // click code here 
     2136                        SetAxis/A 
     2137                        break 
     2138                case -1: // control being killed 
     2139                        break 
     2140        endswitch 
     2141 
     2142        return 0 
     2143End 
     2144 
     2145Function EC_HelpButtonProc(ba) : ButtonControl 
     2146        STRUCT WMButtonAction &ba 
     2147 
     2148        switch( ba.eventCode ) 
     2149                case 2: // mouse up 
     2150                        // click code here 
     2151                        DoAlert 0,"The Event Correction help file has not been written yet" 
     2152                        break 
     2153                case -1: // control being killed 
     2154                        break 
     2155        endswitch 
     2156 
     2157        return 0 
     2158End 
     2159 
     2160Function EC_DoneButtonProc(ba) : ButtonControl 
     2161        STRUCT WMButtonAction &ba 
     2162 
     2163        switch( ba.eventCode ) 
     2164                case 2: // mouse up 
     2165                        // click code here 
     2166                        DoWindow/K EventCorrectionPanel 
     2167                        break 
     2168                case -1: // control being killed 
     2169                        break 
     2170        endswitch 
     2171 
     2172        return 0 
     2173End 
     2174 
     2175 
     2176 
     2177 
     2178////////////// 
     2179 
     2180 
     2181 
     2182// make sure that the bins are defined and the waves exist before 
     2183// trying to draw the panel 
     2184// 
     2185Macro Show_CustomBinPanel() 
     2186        DoWindow/F CustomBinPanel 
     2187        if(V_flag ==0) 
     2188                Init_CustomBins() 
     2189                CustomBinPanel() 
     2190        EndIf 
     2191End 
     2192 
     2193 
     2194Function Init_CustomBins() 
     2195 
     2196        NVAR nSlice = root:Packages:NIST:gEvent_nslices 
     2197        NVAR t_longest = root:Packages:NIST:gEvent_t_longest 
     2198 
     2199        Variable/G root:Packages:NIST:gEvent_ForceTmaxBin=1             //==1 to enforce t_longest in user-defined custom bins 
     2200 
     2201        SetDataFolder root:Packages:NIST:Event: 
     2202                 
     2203        Make/O/D/N=(nSlice) timeWidth 
     2204        Make/O/D/N=(nSlice+1) binEndTime,binCount 
     2205         
     2206        timeWidth = t_longest/nslice 
     2207        binEndTime = p 
     2208        binCount = p+1   
     2209         
     2210        SetDataFolder root: 
     2211         
     2212        return(0) 
     2213End 
     2214 
     2215////////////////         
     2216// 
     2217// Allow custom definitions of the bin widths 
     2218// 
     2219// Define by the number of bins, and the time width of each bin 
     2220// 
     2221// This shares the number of slices and the maximum time with the main panel 
     2222// 
     2223Proc CustomBinPanel() 
     2224        PauseUpdate; Silent 1           // building window... 
     2225        NewPanel /W=(130,44,851,455)/K=2 /N=CustomBinPanel 
     2226        DoWindow/C CustomBinPanel 
     2227        ModifyPanel fixedSize=1//,noEdit =1 
     2228        SetDrawLayer UserBack 
     2229         
     2230        Button button0,pos={654,42}, size={50,20},title="Done",fSize=12 
     2231        Button button0,proc=CB_Done_Proc 
     2232        Button button1,pos={663,14},size={40,20},proc=CB_HelpButtonProc,title="?" 
     2233        Button button2,pos={216,42},size={80,20},title="Update",proc=CB_UpdateWavesButton        
     2234        SetVariable setvar1,pos={23,13},size={160,20},title="Number of slices",fSize=12 
     2235        SetVariable setvar1,proc=CB_NumSlicesSetVarProc,value=root:Packages:NIST:gEvent_nslices 
     2236        SetVariable setvar2,pos={24,44},size={160,20},title="Max Time (s)",fSize=12 
     2237        SetVariable setvar2,value=root:Packages:NIST:gEvent_t_longest    
     2238 
     2239        CheckBox chkbox1,pos={216,14},title="Enforce Max Time?" 
     2240        CheckBox chkbox1,variable = root:Packages:NIST:gEvent_ForceTmaxBin 
     2241        Button button3,pos={500,14},size={90,20},proc=CB_SaveBinsButtonProc,title="Save Bins" 
     2242        Button button4,pos={500,42},size={100,20},proc=CB_ImportBinsButtonProc,title="Import Bins"       
     2243         
     2244         
     2245         
     2246        SetDataFolder root:Packages:NIST:Event: 
     2247 
     2248        Display/W=(291,86,706,395)/HOST=CustomBinPanel/N=BarGraph binCount vs binEndTime 
     2249        ModifyGraph mode=5 
     2250        ModifyGraph marker=19 
     2251        ModifyGraph lSize=2 
     2252        ModifyGraph rgb=(0,0,0) 
     2253        ModifyGraph msize=2 
     2254        ModifyGraph hbFill=2 
     2255        ModifyGraph gaps=0 
     2256        ModifyGraph usePlusRGB=1 
     2257        ModifyGraph toMode=1 
     2258        ModifyGraph useBarStrokeRGB=1 
     2259        ModifyGraph standoff=0 
     2260        SetAxis left 0,* 
     2261        Label bottom "\\Z14Time (seconds)" 
     2262        Label left "\\Z14Number of Events" 
     2263        SetActiveSubwindow ## 
     2264         
     2265        // and the table 
     2266        Edit/W=(13,87,280,394)/HOST=CustomBinPanel/N=T0 
     2267        AppendToTable/W=CustomBinPanel#T0 timeWidth,binEndTime 
     2268        ModifyTable width(Point)=40 
     2269        SetActiveSubwindow ## 
     2270         
     2271        SetDataFolder root: 
     2272         
     2273EndMacro 
     2274 
     2275// save the bins - use Igor Text format 
     2276Function CB_SaveBinsButtonProc(ba) : ButtonControl 
     2277        STRUCT WMButtonAction &ba 
     2278 
     2279        switch( ba.eventCode ) 
     2280                case 2: // mouse up 
     2281                        // click code here 
     2282 
     2283                        SetDataFolder root:Packages:NIST:Event: 
     2284 
     2285                        Wave timeWidth = timeWidth 
     2286                        Wave binEndTime = binEndTime 
     2287                         
     2288                        Save/T timeWidth,binEndTime                     //will ask for a name 
     2289 
     2290                        break 
     2291                case -1: // control being killed 
     2292                        break 
     2293        endswitch 
     2294 
     2295        SetDataFolder root: 
     2296         
     2297        return 0 
     2298End 
     2299 
     2300// Import the bins - use Igor Text format 
     2301// 
     2302// -- be sure that the number of bins is reset 
     2303// -?- how about the t_longest? - this should be set by the load, not here 
     2304// 
     2305// -- loads in timeWidth and binEndTime 
     2306// 
     2307Function CB_ImportBinsButtonProc(ba) : ButtonControl 
     2308        STRUCT WMButtonAction &ba 
     2309 
     2310        switch( ba.eventCode ) 
     2311                case 2: // mouse up 
     2312                        // click code here 
     2313                        NVAR nSlice = root:Packages:NIST:gEvent_nslices 
     2314 
     2315                        SetDataFolder root:Packages:NIST:Event: 
     2316 
     2317                        // prompt for the load of data 
     2318                        LoadWave/T/O 
     2319                        if(strlen(S_fileName) == 0) 
     2320                                //user cancelled 
     2321                                DoAlert 0,"No file selected, nothing done." 
     2322                                return(0) 
     2323                        endif 
     2324 
     2325                        Wave timeWidth = timeWidth 
     2326                        nSlice = numpnts(timeWidth) 
     2327                         
     2328                        break 
     2329                case -1: // control being killed 
     2330                        break 
     2331        endswitch 
     2332 
     2333        SetDataFolder root: 
     2334         
     2335        return 0 
     2336End 
     2337 
     2338 
     2339 
     2340// 
     2341// can either use the widths as stated -- then the end time may not 
     2342// match the actual end time of the data set 
     2343// 
     2344// -- or -- 
     2345// 
     2346// enforce the end time of the data set to be the end time of the bins, 
     2347// then the last bin width must be reset to force the constraint 
     2348// 
     2349// 
     2350Function CB_UpdateWavesButton(ba) : ButtonControl 
     2351        STRUCT WMButtonAction &ba 
     2352 
     2353        switch( ba.eventCode ) 
     2354                case 2: // mouse up 
     2355                        // click code here 
     2356                        NVAR nSlice = root:Packages:NIST:gEvent_nslices 
     2357                        NVAR t_longest = root:Packages:NIST:gEvent_t_longest 
     2358                        NVAR enforceTmax = root:Packages:NIST:gEvent_ForceTmaxBin 
     2359                         
     2360                        // update the waves, and recalculate everything for the display 
     2361                        SetDataFolder root:Packages:NIST:Event: 
     2362 
     2363                        Wave timeWidth = timeWidth 
     2364                        Wave binEndTime = binEndTime 
     2365                        Wave binCount = binCount 
     2366                         
     2367                        // use the widths as entered 
     2368                        binEndTime[0] = 0 
     2369                        binEndTime[1,] = binEndTime[p-1] + timeWidth[p-1] 
     2370                         
     2371                        // enforce the longest time as the end bin time 
     2372                        // note that this changes the last time width 
     2373                        if(enforceTmax) 
     2374                                binEndTime[nSlice] = t_longest 
     2375                                timeWidth[nSlice-1] = t_longest - binEndTime[nSlice-1] 
     2376                        endif 
     2377                         
     2378                        binCount = p+1 
     2379                        binCount[nSlice] = 0            // last point is zero, just for display 
     2380//                      binCount *= sign(timeWidth)             //to alert to negative time bins 
     2381                         
     2382                        // make the timeWidth bold and red if the widths are negative 
     2383                        WaveStats/Q timeWidth 
     2384                        if(V_min < 0) 
     2385                                ModifyTable/W=CustomBinPanel#T0 style(timeWidth)=1,rgb(timeWidth)=(65535,0,0)                    
     2386                        else 
     2387                                ModifyTable/W=CustomBinPanel#T0 style(timeWidth)=0,rgb(timeWidth)=(0,0,0)                        
     2388                        endif 
     2389                         
     2390                        break 
     2391                case -1: // control being killed 
     2392                        break 
     2393        endswitch 
     2394 
     2395        SetDataFolder root: 
     2396         
     2397        return 0 
     2398End 
     2399 
     2400Function CB_HelpButtonProc(ba) : ButtonControl 
     2401        STRUCT WMButtonAction &ba 
     2402 
     2403        switch( ba.eventCode ) 
     2404                case 2: // mouse up 
     2405                        // click code here 
     2406                        DoAlert 0,"The help file for the bin editor has not been written yet" 
     2407                        break 
     2408                case -1: // control being killed 
     2409                        break 
     2410        endswitch 
     2411 
     2412        return 0 
     2413End 
     2414 
     2415Function CB_Done_Proc(ba) : ButtonControl 
     2416        STRUCT WMButtonAction &ba 
     2417         
     2418        String win = ba.win 
     2419        switch (ba.eventCode) 
     2420                case 2: 
     2421                        DoWindow/K CustomBinPanel 
     2422                        break 
     2423        endswitch 
     2424        return(0) 
     2425End 
     2426 
     2427 
     2428Function CB_NumSlicesSetVarProc(sva) : SetVariableControl 
     2429        STRUCT WMSetVariableAction &sva 
     2430 
     2431        switch( sva.eventCode ) 
     2432                case 1: // mouse up 
     2433                case 2: // Enter key 
     2434                case 3: // Live update 
     2435                        Variable dval = sva.dval 
     2436                        String sval = sva.sval 
     2437                        SetDataFolder root:Packages:NIST:Event: 
     2438 
     2439                        Wave timeWidth = timeWidth 
     2440                        Wave binEndTime = binEndTime 
     2441                         
     2442                        Redimension/N=(dval) timeWidth 
     2443                        Redimension/N=(dval+1) binEndTime,binCount 
     2444                         
     2445                        SetDataFolder root: 
     2446                         
     2447                        break 
     2448                case -1: // control being killed 
     2449                        break 
     2450        endswitch 
     2451 
     2452        return 0 
     2453End 
     2454 
     2455 
     2456/////////////////// 
Note: See TracChangeset for help on using the changeset viewer.