Ignore:
Timestamp:
Nov 30, 2012 5:04:56 PM (10 years ago)
Author:
srkline
Message:

Cleaning up the code a bit, adding comments. Making constant declarations in the Event.ipf and Tisane.ipf static so that they are not entangled.

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

Legend:

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

    r880 r881  
    66// TODO: 
    77// 
     8// -- search for TODO for unresolved issues not on this list 
     9// 
     10// -- add comments to the code as needed 
     11// 
     12// -- write the help file, and link the help buttons to the help docs 
     13// 
     14// -- examples? 
     15// 
     16// -- add the XOP to the distribution package 
     17// 
    818// -- Need to make sure that the rescaledTime and the differentiated time graphs are 
    919//     being properly updated when the data is processed, modified, etc. 
     
    1222//     It's all a stream, just sometimes it's not oscillatory 
    1323// 
    14 // X- fix the log/lin display - it's not working correctly 
    15 //                      I could use ModifyImage and log = 0|1 keyword for the log Z display 
    16 //                      rather than creating a duplicate wave of log(data) 
    17 //                      -- it's in the Function sliceSelectEvent_Proc() 
    1824// 
    1925// -- the slice display "fails" for data sets that have 3 or 4 slices, as the ModifyImage command 
     
    2733//     points. Maybe not kosher, but would clean things up. 
    2834// 
    29 // -- Is there any way to improve the speed of the loader? How could an XOP be structured 
    30 //     for maximum flexibility? Leave the post processing to Igor, but how much for the XOP 
    31 //     to do? And can it handle such large amounts of data to pass back and forth, or 
    32 //     does it need to be written as an operation, rather than a function??? I'd really  
    33 //     rather that Igor handles the memory management, not me, if I write the XOP. 
    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: 
     35// 
     36///////// DONE ////////// 
     37// 
     38// X- memory issues: 
    4039//              -- in LoadEvents -- should I change the MAKE to: 
    4140//                              /I/U is unsigned 32-bit integer (for the time) 
     
    4847//    generate only SP waves. this will at least save some space. 
    4948// 
     49// 
     50// 
     51// x- Is there any way to improve the speed of the loader? How could an XOP be structured 
     52//     for maximum flexibility? Leave the post processing to Igor, but how much for the XOP 
     53//     to do? And can it handle such large amounts of data to pass back and forth, or 
     54//     does it need to be written as an operation, rather than a function??? I'd really  
     55//     rather that Igor handles the memory management, not me, if I write the XOP. 
     56// 
     57// **- as of 11/27, the OSX version of the XOP event loader is about 35x faster for the load! 
     58//    and is taking approx 1.8s/28MB, or about 6.5s/100MB of file. quite reasonable now, and 
     59//    probably a bit faster yet on the PC. 
     60// 
     61// 
     62// X- fix the log/lin display - it's not working correctly 
     63//                      I could use ModifyImage and log = 0|1 keyword for the log Z display 
     64//                      rather than creating a duplicate wave of log(data) 
     65//                      -- it's in the Function sliceSelectEvent_Proc() 
     66// 
    5067// X- add controls to show the bar graph 
    5168// x- add popup for selecting the binning type 
     
    6582 
    6683// 
    67 // These are currently defined in the TISANE procedure file. If that file becomes depricated 
    68 // or is not loaded in, then these lines should be activated, and those in TISANE should also 
    69 // be re-declared as Static, so they will be local to each procedure 
    70 // 
    71 //Static Constant ATXY = 0 
    72 //Static Constant ATXYM = 2 
    73 //Static Constant ATMIR = 1 
    74 //Static Constant ATMAR = 3 
    75 // 
    76 //Static Constant USECSPERTICK=0.1 // microseconds 
    77 //Static Constant TICKSPERUSEC=10 
    78 //Static Constant XBINS=128 
    79 //Static Constant YBINS=128 
     84// These are also defined in the TISANE procedure file. In both files they are declared 
     85// as Static, so they are local to each procedure 
     86// 
     87Static Constant ATXY = 0 
     88Static Constant ATXYM = 2 
     89Static Constant ATMIR = 1 
     90Static Constant ATMAR = 3 
     91 
     92Static Constant USECSPERTICK=0.1 // microseconds 
     93Static Constant TICKSPERUSEC=10 
     94Static Constant XBINS=128 
     95Static Constant YBINS=128 
    8096// 
    8197 
     
    154170        Button button6,pos={378,13},size={40,20},proc=EventModeHelpButtonProc,title="?" 
    155171         
    156         //DrawLine 10,35,490,35 
    157172        Button button1,pos = {10,50}, size={150,20},title="Process Data",fSize=12 
    158173        Button button1,proc=ProcessEventLog_Button 
     
    161176        SetVariable setvar2,pos={330,50},size={160,20},title="Max Time (s)",fSize=12 
    162177        SetVariable setvar2,value=root:Packages:NIST:gEvent_t_longest 
    163         //DrawLine 10,65,490,65 
    164          
    165 //      PopupMenu popup0 title="Bin Spacing",pos={150,90},value="Equal;Fibonacci;Log;" 
     178         
    166179        PopupMenu popup0 title="Bin Spacing",pos={150,90},value="Equal;Fibonacci;Custom;" 
    167180        PopupMenu popup0 proc=BinTypePopMenuProc 
     
    334347// now with the number of slices and max time, process the events 
    335348 
    336  
    337349        NVAR t_longest = root:Packages:NIST:gEvent_t_longest 
    338350        NVAR nslices = root:Packages:NIST:gEvent_nslices 
     
    373385                case "Log":             // execute if case matches expression 
    374386                        SetLogBins(binEndTime,timeWidth,nslices,t_longest) 
     387                        break 
     388                case "Custom":          // execute if case matches expression 
     389                        //bins are set by the user on the panel - assume it's good to go 
    375390                        break 
    376391                default:                                                        // optional default expression executed 
     
    500515                        break 
    501516                case "Custom":          // execute if case matches expression 
    502                         //SetLogBins(binEndTime,nslices,t_longest) 
     517                        //bins are set by the user on the panel - assume it's good to go 
    503518                        break 
    504519                default:                                                        // optional default expression executed 
     
    507522        endswitch 
    508523 
     524// TODO 
     525// the global exists for this switch, but it is not implemented - not sure whether 
     526// it's correct to implement this at all -- 
     527// 
    509528        if(yesSortStream == 1) 
    510529                SortTimeData() 
    511530        endif 
     531         
    512532// index the events before binning 
    513533// if there is a sort of these events, I need to re-index the events for the histogram 
     
    585605 
    586606 
    587  
     607// now before binning, sort the data 
     608// 
     609//this is slow - undoing the sorting and starting over, but if you don't, 
     610// you'll never be able to undo the sort 
     611// 
    588612Function SortTimeData() 
    589613 
    590 // now before binning, sort the data 
    591  
    592         //this is slow - undoing the sorting and starting over, but if you don't, 
    593         // you'll never be able to undo the sort 
    594         // 
     614 
    595615        SetDataFolder root:Packages:NIST:Event: 
    596616 
    597617        KillWaves/Z OscSortIndex 
    598 //      Print WaveExists($"root:Packages:NIST:Event:OscSortIndex") 
    599618         
    600619        if(WaveExists($"root:Packages:NIST:Event:OscSortIndex") == 0 ) 
     
    629648End 
    630649 
    631  
     650// TODO 
     651// either get this to work, or scrap it entirely. it currently isn't on the popup 
     652// so it can't be accessed 
    632653Function SetLogBins(binEndTime,timeWidth,nslices,t_longest) 
    633654        Wave binEndTime,timeWidth 
     
    700721 
    701722 
    702  
     723// TODO: 
     724// 
     725// What, if anything is different about the OSC or STREAM load? 
     726// I think that only the processing is different. so this could be 
     727// consolidated into a single loader. 
     728// 
     729// Would TISANE or TOF need a different loader? 
     730// 
    703731Function LoadEventLog_Button(ctrlName) : ButtonControl 
    704732        String ctrlName 
     
    750778 
    751779#if (exists("EventLoadWave")==4) 
    752  
    753780        LoadEvents_XOP() 
    754  
    755781#else 
    756          
    757782        LoadEvents() 
    758  
    759783#endif   
    760784 
     
    800824         
    801825#if (exists("EventLoadWave")==4) 
    802  
    803826        LoadEvents_XOP() 
    804  
    805827#else 
    806          
    807828        LoadEvents() 
    808  
    809829#endif   
    810830         
     
    873893 
    874894 
    875  
     895// TODO 
    876896// this "fails" for data sets that have 3 or 4 slices, as the ModifyImage command 
    877897// interprets the data as being RGB - and so does nothing. 
     
    935955//              Print (K0 & 0x20000000)/536870912               //bit 29 only, shift by 2^29 
    936956// 
     957// This is duplicated by the XOP, but the Igor code allows quick access to print out 
     958// all of the gorey details of the events and every little bit of them. the print 
     959// statements and flags are kept for this reason, so the code is a bit messy. 
    937960// 
    938961Function LoadEvents() 
     
    10471070         
    10481071 
    1049 Print "(Igor) numT0 = ",numT0    
    1050 Print "num0 = ",num0     
    1051 Print "num1 = ",num1     
    1052 Print "num2 = ",num2     
    1053 Print "num3 = ",num3     
     1072        Print "(Igor) numT0 = ",numT0    
     1073        Print "num0 = ",num0     
     1074        Print "num1 = ",num1     
     1075        Print "num2 = ",num2     
     1076        Print "num3 = ",num3     
    10541077         
    10551078// 
     
    10691092        sprintf tmpStr,"numXYevents = %d\r",numXYevents 
    10701093        dispStr += tmpStr 
    1071 //      sprintf tmpStr,"XY = num0 = %d\r",num0 
    1072 //      dispStr += tmpStr 
    1073 //      sprintf tmpStr,"\rXY time = num2 = %d\rtime MSW = num1 = %d",num2,num1 
    1074 //      dispStr += tmpStr 
    1075 //      sprintf tmpStr,"XY time = num2 = %d\r",num2 
    1076 //      dispStr += tmpStr 
    1077 //      sprintf tmpStr,"time MSW = num1 = %d\r",num1 
    1078 //      dispStr += tmpStr 
    10791094        sprintf tmpStr,"PP = %d  :  ",numPP 
    10801095        dispStr += tmpStr 
     
    11781193                type = (dataval & 0xC0000000)/1073741824                //right shift by 2^30 
    11791194                 
     1195                // 
     1196                // The defintions of the event types 
    11801197                // 
    11811198                //Constant ATXY = 0 
     
    13991416////////////// 
    14001417// 
    1401 // This calls the XOP, as an operation 
     1418// This calls the XOP, as an operation to load the events 
     1419// 
     1420// -- it's about 35x faster than the Igor code, so I guess that's OK. 
    14021421// 
    14031422// 
     
    14841503                EventLoadWave/N=EventWave  filepathstr 
    14851504        endif 
    1486  
    14871505#endif 
    14881506 
     
    15381556        sprintf tmpStr,"numXYevents = %d\r",numXYevents 
    15391557        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 
    15481558        sprintf tmpStr,"PP = %d  :  ",numPP 
    15491559        dispStr += tmpStr 
     
    15891599                ModifyGraph toMode=1 
    15901600                ModifyGraph useBarStrokeRGB=1 
    1591         //      ModifyGraph log=1 
    15921601                ModifyGraph standoff=0 
    15931602                SetAxis left 0,* 
    15941603                Label bottom "\\Z14Time (seconds)" 
    15951604                Label left "\\Z14Number of Events" 
    1596         //      SetAxis left 0.1,4189 
    1597         //      SetAxis bottom 0.0001,180.84853 
    15981605        endif 
    15991606End 
     
    16491656 
    16501657//////// procedures to be able to export the slices as RAW VAX files. 
    1651  
     1658// 
    16521659// 1- load the raw data file to use the header (it must already be in RAW) 
    16531660// 1.5- copy the raw data to the temp folder (STO) 
     
    17551762// -- see the related thread on the mailing list 
    17561763// 
    1757  
    1758 // 
    1759 // Now see if this can be succesfully applied to the timeslicing data sets 
    1760 // -- talk to Jeff about what he's gotten implemented, and what's still missing 
    1761 // - both in timeslicing, and in TISANE 
    1762 // - un-scale the wave? or make it work as 128x128 
    1763  
    1764 Function Setup_JointHistogram() 
    1765  
    1766 //      tic() 
    1767  
    1768         make/D /o/n=1000000 data1=gnoise(1), data2=gnoise(1) 
    1769         make/D /o/n=(25,25) myHist 
    1770         setscale x,-3,3,myHist 
    1771         setscale y,-3,3,myHist 
    1772         IndexForHistogram(data1,data2,myhist) 
    1773         Wave index=SavedIndex 
    1774         JointHistogram(data1,data2,myHist,index) 
    1775         NewImage myHist 
    1776          
    1777 //      toc() 
    1778          
    1779 End 
     1764//Function Setup_JointHistogram() 
     1765// 
     1766////    tic() 
     1767// 
     1768//      make/D /o/n=1000000 data1=gnoise(1), data2=gnoise(1) 
     1769//      make/D /o/n=(25,25) myHist 
     1770//      setscale x,-3,3,myHist 
     1771//      setscale y,-3,3,myHist 
     1772//      IndexForHistogram(data1,data2,myhist) 
     1773//      Wave index=SavedIndex 
     1774//      JointHistogram(data1,data2,myHist,index) 
     1775//      NewImage myHist 
     1776//       
     1777////    toc() 
     1778//       
     1779//End 
    17801780 
    17811781 
     
    17991799 
    18001800 
    1801 // need a way of visualizing the bin spacing / number of bins vs the full time of the data collection 
    1802 // then set the range of the source to send to the joint histogram operation 
    1803 // to assign to arrays (or a 3D wave) 
    1804 // 
    1805 // -- see my model with the "layered" form factor - or whatever I called it. That shows different 
    1806 // binning and visualizing as bar graphs. 
    1807 // 
    1808 // -- just need to send x2pnt or findLevel, or something similar to define the POINT 
     1801// histogram with a point range 
     1802// 
     1803// x- just need to send x2pnt or findLevel, or something similar to define the POINT 
    18091804// values 
    18101805// 
    1811 // can also speed this up since the index only needs to be done once, so the 
     1806// x- can also speed this up since the index only needs to be done once, so the 
    18121807// histogram operation can be done separately, as the bins require 
    18131808// 
     
    18671862 
    18681863 
    1869 /////// 
    1870 //// @ IgorExchange 
    1871 ////TicToc 
    1872 ////Posted April 16th, 2009 by bgallarda 
    1873 ////    ¥       in Programming 6.10.x 
    1874 //       
    1875 //function tic() 
    1876 //      variable/G tictoc = startMSTimer 
    1877 //end 
    1878 //  
    1879 //function toc() 
    1880 //      NVAR/Z tictoc 
    1881 //      variable ttTime = stopMSTimer(tictoc) 
    1882 //      printf "%g seconds\r", (ttTime/1e6) 
    1883 //      killvariables/Z tictoc 
    1884 //end 
    1885 // 
    1886 // 
    1887 //Function testTicToc() 
    1888 //  
    1889 //      tic() 
    1890 //      variable i 
    1891 //      For(i=0;i<10000;i+=1) 
    1892 //              make/O/N=512 temp = gnoise(2) 
    1893 //              FFT temp 
    1894 //      Endfor 
    1895 //      killwaves/z temp 
    1896 //      toc() 
    1897 //End 
    1898 // 
    1899 //////////////// 
    1900  
    19011864 
    19021865////////////// Post-processing of the event mode data 
     
    20932056                        SetDataFolder root:Packages:NIST:Event: 
    20942057 
    2095                         //SVAR filename = root:Packages:NIST:gEvent_logfile 
    2096                         //NVAR nslices = root:Packages:NIST:gEvent_nslices 
    20972058                        NVAR t_longest = root:Packages:NIST:gEvent_t_longest 
    20982059                        SVAR dispStr = root:Packages:NIST:gEventDisplayString 
     
    21082069                        endif 
    21092070                         
    2110                          
    21112071                        Wave timePt=timePt 
    21122072 
     
    21762136 
    21772137 
    2178 ////////////// 
    2179  
    2180  
    2181  
     2138//////////////   Custom Bins  ///////////////////// 
     2139// 
     2140// 
     2141// 
    21822142// make sure that the bins are defined and the waves exist before 
    21832143// trying to draw the panel 
     
    22412201        Button button3,pos={500,14},size={90,20},proc=CB_SaveBinsButtonProc,title="Save Bins" 
    22422202        Button button4,pos={500,42},size={100,20},proc=CB_ImportBinsButtonProc,title="Import Bins"       
    2243          
    2244          
    2245          
     2203                 
    22462204        SetDataFolder root:Packages:NIST:Event: 
    22472205 
     
    22742232 
    22752233// save the bins - use Igor Text format 
     2234// 
    22762235Function CB_SaveBinsButtonProc(ba) : ButtonControl 
    22772236        STRUCT WMButtonAction &ba 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/TISANE.ipf

    r871 r881  
    66//Functions to deal with TISANE data 
    77 
    8 Constant ATXY = 0 
    9 Constant ATXYM = 2 
    10 Constant ATMIR = 1 
    11 Constant ATMAR = 3 
    12  
    13 Constant USECSPERTICK=0.1 // microseconds 
    14 Constant TICKSPERUSEC=10 
    15 Constant XBINS=128 
    16 Constant YBINS=128 
     8Static Constant ATXY = 0 
     9Static Constant ATXYM = 2 
     10Static Constant ATMIR = 1 
     11Static Constant ATMAR = 3 
     12 
     13Static Constant USECSPERTICK=0.1 // microseconds 
     14Static Constant TICKSPERUSEC=10 
     15Static Constant XBINS=128 
     16Static Constant YBINS=128 
    1717 
    1818Proc Show_TISANE_Panel() 
Note: See TracChangeset for help on using the changeset viewer.