- Timestamp:
- Nov 30, 2012 3:43:34 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/EventModeProcessing.ipf
r877 r880 12 12 // It's all a stream, just sometimes it's not oscillatory 13 13 // 14 // -- fix the log/lin display - it's not working correctly14 // X- fix the log/lin display - it's not working correctly 15 15 // I could use ModifyImage and log = 0|1 keyword for the log Z display 16 16 // rather than creating a duplicate wave of log(data) 17 17 // -- it's in the Function sliceSelectEvent_Proc() 18 18 // 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) 21 25 // 22 26 // -- Add a switch to allow Sorting of the Stream data to remove the "time-reversed" data … … 29 33 // rather that Igor handles the memory management, not me, if I write the XOP. 30 34 // 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 // 31 50 // X- add controls to show the bar graph 32 51 // x- add popup for selecting the binning type … … 39 58 // size, then a second time to actualy process the events. Would it be faster to insert points 40 59 // 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)) 42 61 // 43 62 // … … 94 113 Variable/G root:Packages:NIST:gSortStreamEvents = 0 // ==1 to sort the event stream, a last resort for a stream of data 95 114 115 Variable/G root:Packages:NIST:gEvent_ForceTmaxBin=1 //==1 to enforce t_longest in user-defined custom bins 116 96 117 NVAR nslices = root:Packages:NIST:gEvent_nslices 97 118 … … 143 164 144 165 // 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 146 168 147 169 CheckBox chkbox2,pos={20,95},title="Log Intensity",value=1 … … 185 207 End 186 208 209 Function 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 225 End 226 187 227 Function ShowBinDetailsButtonProc(ba) : ButtonControl 188 228 STRUCT WMButtonAction &ba … … 274 314 endif 275 315 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) 276 319 277 320 return(0) … … 304 347 Make/O/D/N=(128,128) tmpData 305 348 Make/O/D/N=(nslices+1) binEndTime,binCount 349 Make/O/D/N=(nslices) timeWidth 350 Wave timeWidth = timeWidth 306 351 Wave binEndTime = binEndTime 307 352 Wave binCount = binCount … … 321 366 strswitch(binTypeStr) // string switch 322 367 case "Equal": // execute if case matches expression 323 SetLinearBins(binEndTime, nslices,t_longest)368 SetLinearBins(binEndTime,timeWidth,nslices,t_longest) 324 369 break // exit from switch 325 370 case "Fibonacci": // execute if case matches expression 326 SetFibonacciBins(binEndTime, nslices,t_longest)371 SetFibonacciBins(binEndTime,timeWidth,nslices,t_longest) 327 372 break 328 373 case "Log": // execute if case matches expression 329 SetLogBins(binEndTime, nslices,t_longest)374 SetLogBins(binEndTime,timeWidth,nslices,t_longest) 330 375 break 331 376 default: // optional default expression executed 332 377 DoAlert 0,"No match for bin type, Equal bins used" 333 SetLinearBins(binEndTime, nslices,t_longest)378 SetLinearBins(binEndTime,timeWidth,nslices,t_longest) 334 379 endswitch 335 380 … … 376 421 p2 = numpnts(rescaledTime)-1 //set to the last point if it's off the end 377 422 Endif 378 Print p1,p2423 // Print p1,p2 379 424 380 425 … … 428 473 Make/O/D/N=(128,128) tmpData 429 474 Make/O/D/N=(nslices+1) binEndTime,binCount//,binStartTime 475 Make/O/D/N=(nslices) timeWidth 430 476 Wave binEndTime = binEndTime 431 // Wave binStartTime = binStartTime 477 Wave timeWidth = timeWidth 432 478 Wave binCount = binCount 433 479 … … 445 491 strswitch(binTypeStr) // string switch 446 492 case "Equal": // execute if case matches expression 447 SetLinearBins(binEndTime, nslices,t_longest)493 SetLinearBins(binEndTime,timeWidth,nslices,t_longest) 448 494 break // exit from switch 449 495 case "Fibonacci": // execute if case matches expression 450 SetFibonacciBins(binEndTime, nslices,t_longest)496 SetFibonacciBins(binEndTime,timeWidth,nslices,t_longest) 451 497 break 452 498 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) 454 503 break 455 504 default: // optional default expression executed 456 505 DoAlert 0,"No match for bin type, Equal bins used" 457 SetLinearBins(binEndTime, nslices,t_longest)506 SetLinearBins(binEndTime,timeWidth,nslices,t_longest) 458 507 endswitch 459 508 … … 489 538 p2 = numpnts(rescaledTime)-1 //set to the last point if it's off the end 490 539 Endif 491 Print p1,p2540 // Print p1,p2 492 541 493 542 … … 561 610 562 611 563 Function SetLinearBins(binEndTime, nslices,t_longest)564 Wave binEndTime 612 Function SetLinearBins(binEndTime,timeWidth,nslices,t_longest) 613 Wave binEndTime,timeWidth 565 614 Variable nslices,t_longest 566 615 … … 575 624 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 576 625 626 timeWidth = binEndTime[p+1]-binEndTime[p] 627 577 628 return(0) 578 629 End 579 630 580 631 581 Function SetLogBins(binEndTime, nslices,t_longest)582 Wave binEndTime 632 Function SetLogBins(binEndTime,timeWidth,nslices,t_longest) 633 Wave binEndTime,timeWidth 583 634 Variable nslices,t_longest 584 635 … … 597 648 binEndTime[ii+1] = t_longest //otherwise floating point errors such that the last time point is off the end of the Binary search 598 649 650 timeWidth = binEndTime[p+1]-binEndTime[p] 651 599 652 return(0) 600 653 End … … 619 672 end 620 673 621 Function SetFibonacciBins(binEndTime, nslices,t_longest)622 Wave binEndTime 674 Function SetFibonacciBins(binEndTime,timeWidth,nslices,t_longest) 675 Wave binEndTime,timeWidth 623 676 Variable nslices,t_longest 624 677 … … 640 693 binEndTime[ii+1] = t_longest //otherwise floating point errors such that the last time point is off the end of the Binary search 641 694 695 timeWidth = binEndTime[p+1]-binEndTime[p] 696 642 697 return(0) 643 698 End … … 650 705 651 706 NVAR mode=root:Packages:NIST:gEvent_mode 707 Variable err=0 652 708 653 709 if(mode == 0) 654 Stream_LoadEventLog("") 710 err = Stream_LoadEventLog("") 711 if(err == 1) 712 return(0) // user cancelled from file load 713 endif 655 714 endif 656 715 657 716 if(mode == 1) 658 Osc_LoadEventLog("") 717 err = Osc_LoadEventLog("") 718 if(err == 1) 719 return(0) // user cancelled from file load 720 endif 659 721 endif 660 722 … … 681 743 Open/R/D/F=fileFilters fileref 682 744 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 683 756 684 757 LoadEvents() 685 758 759 #endif 760 686 761 SetDataFolder root:Packages:NIST:Event: 687 762 … … 718 793 Open/R/D/F=fileFilters fileref 719 794 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 720 806 721 807 LoadEvents() 808 809 #endif 722 810 723 811 SetDataFolder root:Packages:NIST:Event: … … 740 828 741 829 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 743 833 Function CleanupTimes(xLoc,yLoc,timePt) 744 834 Wave xLoc,yLoc,timePt 745 835 746 836 // 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 749 840 ii=num 750 841 do 751 842 ii -= 1 752 843 if(timePt[ii] == 0 && xLoc[ii] == 0 && yLoc[ii] == 0) 753 DeletePoints ii, 1, xLoc,yLoc,timePt844 numToRemove += 1 754 845 endif 755 846 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 756 851 757 852 return(0) … … 769 864 endif 770 865 866 NVAR selectedslice = root:Packages:NIST:gEvent_tsdisp 867 868 sliceSelectEvent_Proc("", selectedslice, "", "") 869 771 870 SetDataFolder root: 871 772 872 End 773 873 … … 805 905 806 906 Wave rescaledTime = root:Packages:NIST:Event:rescaledTime 807 907 908 SetDataFolder root:Packages:NIST:Event: 909 808 910 Differentiate rescaledTime/D=rescaledTime_DIF 809 911 // Display rescaledTime,rescaledTime_DIF … … 817 919 Label bottom "\\Z14Event number" 818 920 endif 921 922 SetDataFolder root: 819 923 820 924 return(0) … … 939 1043 Close fileref 940 1044 // done counting the number of XY events 1045 printf("Igor pre-scan done in ") 941 1046 toc() 942 943 Print "numT0 = ",numT0 1047 1048 1049 Print "(Igor) numT0 = ",numT0 1050 Print "num0 = ",num0 1051 Print "num1 = ",num1 1052 Print "num2 = ",num2 1053 Print "num3 = ",num3 944 1054 945 1055 // … … 974 1084 dispStr += tmpStr 975 1085 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 977 1088 978 1089 Make/O/U/N=(numXYevents) xLoc,yLoc … … 1087 1198 if(dataval == 0 && RemoveBadEvents == 1) 1088 1199 numRemoved += 1 1200 //Print "zero at ii= ",ii 1089 1201 break //don't increment ii 1090 1202 endif … … 1268 1380 while(1) 1269 1381 1270 1271 1382 Close fileref 1272 1383 1384 printf("Igor full file read done in ") 1273 1385 toc() 1274 1386 1275 Print "Events removed = ",numRemoved1276 1277 sPrintf tmpStr,"\rBad Events = numBad= %d (%g %% of events)",numBad,numBad/numXYevents*1001387 Print "Events removed (Igor) = ",numRemoved 1388 1389 sPrintf tmpStr,"\rBad Rollover Events = %d (%g %% of events)",numBad,numBad/numXYevents*100 1278 1390 dispStr += tmpStr 1279 1391 sPrintf tmpStr,"\rTotal Events Removed = %d (%g %% of events)",numRemoved,numRemoved/numXYevents*100 1392 dispStr += tmpStr 1280 1393 SetDataFolder root: 1281 1394 … … 1284 1397 End 1285 1398 1286 /// 1399 ////////////// 1400 // 1401 // This calls the XOP, as an operation 1402 // 1403 // 1404 Function 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 1464 tic() 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 1568 End 1569 1570 ////////////// 1287 1571 1288 1572 Proc BinEventBarGraph() … … 1307 1591 // ModifyGraph log=1 1308 1592 ModifyGraph standoff=0 1593 SetAxis left 0,* 1309 1594 Label bottom "\\Z14Time (seconds)" 1310 1595 Label left "\\Z14Number of Events" … … 1322 1607 String fldrSav0= GetDataFolder(1) 1323 1608 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)=2181609 Edit/W=(498,699,1003,955) /K=1/N=BinEventTable binCount,binEndTime,timeWidth 1610 ModifyTable format(Point)=1,sigDigits(binEndTime)=8,width(binEndTime)=100 1326 1611 SetDataFolder fldrSav0 1327 1612 endif … … 1343 1628 ModifyGraph marker=19 1344 1629 ModifyGraph rgb(rescaledTime)=(0,0,0) 1345 ModifyGraph msize= 21630 ModifyGraph msize=1 1346 1631 // SetAxis/A=2 left //only autoscale the visible data (based on the bottom limits) 1347 1632 // SetAxis bottom 0,1500 … … 1613 1898 // 1614 1899 //////////////// 1900 1901 1902 ////////////// Post-processing of the event mode data 1903 1904 Macro 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 1933 EndMacro 1934 1935 Function 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 1954 End 1955 1956 Function 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 1986 End 1987 1988 Function 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 2018 End 2019 2020 // points removed are inclusive 2021 // 2022 // put both cursors on the same point to remove just that single point 2023 // 2024 Function 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 2055 End 2056 2057 // un-sort the data first, then save it 2058 Function 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 2082 End 2083 2084 // this duplicates all of the bits that would be done if the "load" button was pressed 2085 // 2086 // 2087 Function 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 2127 End 2128 2129 2130 Function 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 2143 End 2144 2145 Function 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 2158 End 2159 2160 Function 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 2173 End 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 // 2185 Macro Show_CustomBinPanel() 2186 DoWindow/F CustomBinPanel 2187 if(V_flag ==0) 2188 Init_CustomBins() 2189 CustomBinPanel() 2190 EndIf 2191 End 2192 2193 2194 Function 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) 2213 End 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 // 2223 Proc 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 2273 EndMacro 2274 2275 // save the bins - use Igor Text format 2276 Function 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 2298 End 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 // 2307 Function 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 2336 End 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 // 2350 Function 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 2398 End 2399 2400 Function 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 2413 End 2414 2415 Function 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) 2425 End 2426 2427 2428 Function 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 2453 End 2454 2455 2456 ///////////////////
Note: See TracChangeset
for help on using the changeset viewer.