source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Marquee.ipf @ 779

Last change on this file since 779 was 779, checked in by srkline, 12 years ago

fixed a bug in ILL_DataReadWrite that always set the sample aperture diameter to 10 mm. It appears that the raw data files have zero as the aperture diameter, so if zero is found, 10 is returned. Otheriwse, if a value is found, it is returned.

Added a few tweaks to the Histogram Pair procedures on the Marquee.

deleted extra pragma statement from CircSectAve?.ipf

File size: 22.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5////////////
6// vers 1.21 3 may 06 total transmission incorporated (BSG)
7//
8//**************************
9// Vers 1.2 091901
10//
11// marquee functions are used to:
12//
13// locate the beamcenter
14// set the (x,y) box coordinates for the sum for transmission calculation
15// read out coordinates
16// do a "box sum" of the same box over a range of files
17// do a 2D Gaussian fit over a selected range
18// do a save of the current image (with colorBar) - as a graphics image
19//
20//***************************
21
22//sums the data counts in the box specified by (x1,y1) to (x2,y2)
23//assuming that x1<x2, and y1<y2
24//the x,y values must also be in axis coordinates[0,127] NOT (1,128) detector coords.
25//
26// accepts arbitrary detector coordinates. calling function is responsible for
27// keeping selection in bounds
28Function SumCountsInBox(x1,x2,y1,y2,type)
29        Variable x1,x2,y1,y2
30        String type
31       
32        Variable counts = 0,ii,jj
33       
34        String dest =  "root:Packages:NIST:"+type
35       
36        //check for logscale data, but don't change the data
37        NVAR gIsLogScale = $(dest + ":gIsLogScale")
38        if (gIsLogScale)
39                wave w=$(dest + ":linear_data")
40        else
41                wave w=$(dest + ":data")
42        endif
43       
44        ii=x1
45        jj=y1
46        do
47                do
48                        counts += w[ii][jj]
49                        jj+=1
50                while(jj<=y2)
51                jj=y1
52                ii+=1
53        while(ii<=x2)
54       
55        Return (counts)
56End
57
58
59//from a marquee selection:
60//calculates the sum of counts in the box, and records this count value in
61//globals for both patch and Trans routines, then records the box coordinates
62//and the count value for the box in the header of the (currently displayed)
63//empty beam file for use later when calculating transmissions of samples
64//these values are written to unused (analysis) fields in the data header
65//4 integers and one real value are written
66//
67//re-written to work with Transmission panel as well as PatchPanel
68//which now bothe work from the same folder (:Patch)
69//
70Function SetXYBoxCoords() :  GraphMarquee
71
72        GetMarquee left,bottom
73        if(V_flag == 0)
74                Abort "There is no Marquee"
75        Endif
76        SVAR dispType=root:myGlobals:gDataDisplayType
77        if(cmpstr(dispType,"SAM")!=0)
78                DoAlert 0, "You can only use SetXYBox on SAM data files"
79                return(1)
80        endif
81        //printf "marquee left in bottom axis terms: %g\r",round(V_left)
82        //printf "marquee right in bottom axis terms: %g\r",round(V_right)
83        //printf "marquee top in left axis terms: %g\r",round(V_top)
84        //printf "marquee bottom in left axis terms: %g\r",round(V_bottom)
85        Variable x1,x2,y1,y2
86        x1 = round(V_left)
87        x2 = round(V_right)
88        y1 = round(V_bottom)
89        y2 = round(V_top)
90       
91        KeepSelectionInBounds(x1,x2,y1,y2)
92       
93        //check to make sure that Patch and Trans data folders exist for writing of global variables
94        If( ! (DataFolderExists("root:myGlobals:Patch"))  )
95                Execute "InitializePatchPanel()"
96        Endif
97        //check to make sure that Patch and Trans data folders exist for writing of global variables
98        If( ! (DataFolderExists("root:myGlobals:TransHeaderInfo"))  )
99                Execute "InitializeTransPanel()"
100        Endif
101       
102        //write string as keyword-packed string, to use IGOR parsing functions
103        String msgStr = "X1="+num2str(x1)+";"
104        msgStr += "X2="+num2str(x2)+";"
105        msgStr += "Y1="+num2str(y1)+";"
106        msgStr += "Y2="+num2str(y2)+";"
107        String/G root:myGlobals:Patch:gPS3 = msgStr
108        String/G root:myGlobals:Patch:gEmpBox = msgStr
109        //changing this global wil update the display variable on the TransPanel
110        String/G root:myGlobals:TransHeaderInfo:gBox = msgStr
111       
112        //sum the counts in the patch - working on the SAM data, to be sure that it's normalized
113        //to the same monitor counts and corrected for detector deadtime
114        String type = "SAM"
115        Variable counts
116        counts = SumCountsInBox(x1,x2,y1,y2,type)
117        Print " marquee counts =",counts
118        //Set the global gTransCts
119        Variable/G root:myGlobals:Patch:gTransCts = counts
120       
121        //now change the extra variables in the empty beam file
122        //get the filename from the SAM folder (there will only be one file)
123        SVAR partialName = root:Packages:NIST:SAM:FileList
124        //construct valid filename, then prepend path
125        String tempName = FindValidFilename(partialName)
126        Print "in marquee",partialName
127        //Print tempName
128        if(cmpstr(tempName,"")==0)
129                //file not found, get out
130                Abort "file not found, marquee"
131        Endif
132        //name is ok, prepend path to tempName for read routine
133        PathInfo catPathName
134        if (V_flag == 0)
135                //path does not exist - no folder selected
136                Abort "no path selected"
137        else
138                String filename = S_path + tempName
139        endif
140       
141        if(cmpstr(filename,"no file selected")==0)
142                Abort "no file selected"
143        Endif
144       
145        WriteXYBoxToHeader(filename,x1,x2,y1,y2)
146       
147        Print counts, " counts in XY box"
148        WriteBoxCountsToHeader(filename,counts)
149       
150End
151
152//finds the beam center (the centroid) of the selected region
153//and simply prints out the results to the history window
154//values are printed out in detector coordinates, not IGOR coords.
155//
156Function FindBeamCenter() :  GraphMarquee
157
158        //get the current displayed data (so the correct folder is used)
159        SVAR cur_folder=root:myGlobals:gDataDisplayType
160        String dest = "root:Packages:NIST:" + cur_folder
161       
162        Variable xzsum,yzsum,zsum,xctr,yctr
163        Variable left,right,bottom,top,ii,jj,counts
164       
165        // data wave is hard-wired in as the displayed data
166        NVAR dataIsLog=$(dest + ":gIsLogScale")         //check for log-scaling in current data folder
167        if (dataIsLog)
168                wave data=$(dest + ":linear_data")
169        else
170                wave data=$(dest + ":data")
171        endif
172       
173        GetMarquee left,bottom
174        if(V_flag == 0)
175                Print "There is no Marquee"
176        else
177                left = round(V_left)            //get integer values for selection limits
178                right = round(V_right)
179                top = round(V_top)
180                bottom = round(V_bottom)
181               
182                KeepSelectionInBounds(left,right,bottom,top)
183               
184                // selection valid now, calculate beamcenter
185                xzsum = 0
186                yzsum = 0
187                zsum = 0
188                // count over rectangular selection, doing each row, L-R, bottom to top
189                ii = bottom -1
190                do
191                        ii +=1
192                        jj = left-1
193                        do
194                                jj += 1
195                                counts = data[jj][ii]
196                                xzsum += jj*counts
197                                yzsum += ii*counts
198                                zsum += counts
199                        while(jj<right)
200                while(ii<top)
201               
202                xctr = xzsum/zsum
203                yctr = yzsum/zsum
204               
205                // add 1 to each to get to detector coordinates (1,128)
206                // rather than the data array which is [0,127]
207                xctr+=1
208                yctr+=1
209               
210                Print "X-center (in detector coordinates) = ",xctr
211                Print "Y-center (in detector coordinates) = ",yctr
212        endif
213       
214        //back to root folder (redundant)
215        SetDataFolder root:
216       
217End
218
219//still need to error check - out-of-bounds...waves exist.
220// allows a 2D Gaussian fit to a selected region of data in a SANS_Data window
221//puts up a new graph with the fitted contour
222Function Do_2D_Gaussian_Fit() :  GraphMarquee
223        String topWin=WinName(0,1)              //top *graph* window
224        //exit nicely if not in the Data display window
225        if(cmpstr(topWin,"SANS_Data") != 0)
226                DoAlert 0,"2D Gaussian fitting is only available from the Data Display Window"
227                return(1)
228        Endif
229       
230        GetMarquee/K left,bottom
231        Variable x1,x2,y1,y2,qxlo,qxhi,qylo,qyhi
232        if(V_flag == 0)
233                Print "There is no Marquee"
234        else
235                String junk="",df=""
236               
237                //**hard-wired info about the x-y q-scales
238                qxlo = DimOffset(root:myGlobals:q_x_axis,0)
239                qxhi = DimDelta(root:myGlobals:q_x_axis,0) + qxlo
240//              Print "qxlo,qxhi = ",qxlo,qxhi
241                Wave w=$"root:myGlobals:q_y_axis"
242                qylo=w[0]
243                qyhi=w[1]
244//              print "qylo,qyhi = ",qylo,qyhi
245               
246                junk=ImageInfo("SANS_Data","data",0)
247                df=StringByKey("ZWAVEDF", junk,":",";")
248//              print df
249                Duplicate/O $(df+"data") data,data_err
250                data_err=sqrt(data)             //for weighting
251               
252// comment out the SetScale lines if you want the result in terms of pixels as a way of
253// measuring the beam center. Note that you need to ADD ONE to fitted x0 and y0 to get detector
254// coordinates rather than the zero-indexed array. 2D fitting does have the benefit of
255// reporting error bars on the xy (if you believe that 2D gaussian is correct)         
256                SetScale/I x qxlo,qxhi,"",data
257                SetScale/I y qylo,qyhi,"",data
258               
259                Display /W=(10,50,361,351) /K=1
260                AppendImage data
261                ModifyImage data ctab= {*,*,Grays,0}
262                ModifyGraph width={Plan,1,bottom,left}
263                ModifyGraph mirror=2
264                ModifyGraph lowTrip=1e-04
265                ModifyImage data cindex=$"root:myGlobals:NIHColors"
266                SVAR/Z angst = root:Packages:NIST:gAngstStr
267                Label bottom "Qx ("+angst+"\\S-1\\M)"
268                Label left "Qy ("+angst+"\\S-1\\M)"
269
270                //keep selection in-bounds
271                x1=V_left
272                x2=V_right
273                y1=V_bottom
274                y2=V_top
275                KeepSelectionInBounds(x1,x2,y1,y2)
276
277                //cross correlation coefficent (K6) must be between 0 and 1, need constraints
278                Make/O/T/N=2 temp_constr
279                temp_constr = {"K6>0","K6<1"}
280               
281                CurveFit/N Gauss2D data[x1,x2][y1,y2] /I=1 /W=data_err /D /R /A=0 /C=temp_constr
282               
283                Killwaves/Z temp_constr
284        endif
285End
286
287// to save the image, simply invoke the IGOR menu item for saving graphics
288//
289Function SaveSANSGraphic() : GraphMarquee
290       
291        NVAR isDemoVersion=root:myGlobals:isDemoVersion
292        if(isDemoVersion==1)
293                //      comment out in DEMO_MODIFIED version, and show the alert
294                DoAlert 0,"This operation is not available in the Demo version of IGOR"
295        else
296                DoAlert 1,"Do you want the controls too?"
297                if(V_flag==1)
298                        GetMarquee/K/Z
299                        SavePICT /E=-5/SNAP=1
300                else
301                        DoIGORMenu "File","Save Graphics"
302                endif
303        endif
304End
305
306//does a sum over each of the files in the list over the specified range
307// x,y are assumed to already be in-bounds of the data array
308// output is dumped to the command window
309//
310Function DoBoxSum(fileStr,x1,x2,y1,y2,type)
311        String fileStr
312        Variable x1,x2,y1,y2
313        String type
314       
315        //parse the list of file numbers
316        String fileList="",item="",pathStr="",fullPath=""
317        Variable ii,num,err,cts
318       
319        PathInfo catPathName
320        If(V_Flag==0)
321                Abort "no path selected"
322        Endif
323        pathStr = S_Path
324       
325        fileList=ParseRunNumberList(fileStr)
326        num=ItemsInList(fileList,",")
327       
328        //loop over the list
329        //add each file to SAM (to normalize to monitor counts)
330        //sum over the box
331        //print the results
332        Make/O/N=(num) FileID,BoxCounts
333        Print "Results are stored in root:FileID and root:BoxCounts waves"
334        for(ii=0;ii<num;ii+=1)
335                item=StringFromList(ii,fileList,",")
336                FileID[ii] = GetRunNumFromFile(item)            //do this here, since the list is now valid
337                fullPath = pathStr+item
338                ReadHeaderAndData(fullPath)
339//              String/G root:myGlobals:gDataDisplayType="RAW"
340//              fRawWindowHook()
341                if(cmpstr(type,"SAM")==0)
342                        err = Raw_to_work("SAM")
343                endif
344                String/G root:myGlobals:gDataDisplayType=type
345                fRawWindowHook()
346                cts=SumCountsInBox(x1,x2,y1,y2,type)
347                BoxCounts[ii]=cts
348                Print item+" counts = ",cts
349        endfor
350       
351        DoBoxGraph(FileID,BoxCounts)
352       
353        return(0)
354End
355
356Function DoBoxGraph(FileID,BoxCounts)
357        Wave FileID,BoxCounts
358       
359        Sort FileID BoxCounts,FileID            //sort the waves, in case the run numbers were entered out of numerical order
360       
361        Display /W=(5,44,383,306) BoxCounts vs FileID
362        ModifyGraph mode=4
363        ModifyGraph marker=8
364        ModifyGraph grid=2
365        ModifyGraph mirror=2
366        Label left "Counts (per 10^8 monitor counts)"
367        Label bottom "Run Number"
368       
369        return(0)
370End
371
372//
373// promts the user for a range of file numbers to perform the sum over
374// list must be comma delimited numbers (or dashes) just as in the BuildProtocol panel
375// the (x,y) range is already selected from the marquee
376//
377Function BoxSum() :  GraphMarquee
378        GetMarquee left,bottom
379        if(V_flag == 0)
380                Abort "There is no Marquee"
381        Endif
382        SVAR dispType=root:myGlobals:gDataDisplayType
383        if(cmpstr(dispType,"RealTime")==0)
384                Print "Can't do a BoxSum for a RealTime file"
385                return(1)
386        endif
387        Variable x1,x2,y1,y2
388        x1 = V_left
389        x2 = V_right
390        y1 = V_bottom
391        y2 = V_top
392        KeepSelectionInBounds(x1,x2,y1,y2)
393       
394        String fileStr="",msgStr="Enter a comma-delimited list of run numbers, use dashes for ranges"
395        String type="RAW"
396        Prompt fileStr,msgStr
397        Prompt type,"RAW or Normalized (SAM)",popup,"RAW;SAM;"
398        DoPrompt "Pick the file range",fileStr,type
399        Print "fileStr = ",fileStr
400        printf "(x1,x2) (y1,y2) = (%d,%d) (%d,%d)\r",x1,x2,y1,y2
401       
402        DoBoxSum(fileStr,x1,x2,y1,y2,type)
403       
404        return(0)
405End     
406
407//function that keeps the marquee selection in the range [0,127] inclusive
408// (igor coordinate system)
409// uses pass-by reference!
410//
411// x1 = left
412// x2 = right
413// y1 = bottom
414// y2 = top
415//
416// accepts any detector size
417Function KeepSelectionInBounds(x1,x2,y1,y2)
418        Variable &x1,&x2,&y1,&y2
419       
420        NVAR pixelsX = root:myGlobals:gNPixelsX
421        NVAR pixelsY = root:myGlobals:gNPixelsY
422       
423        //keep selection in-bounds
424        x1 = (round(x1) >= 0) ? round(x1) : 0
425        x2 = (round(x2) <= (pixelsX-1)) ? round(x2) : (pixelsX-1)
426        y1 = (round(y1) >= 0) ? round(y1) : 0
427        y2 = (round(y2) <= (pixelsY-1)) ? round(y2) : (pixelsY-1)
428        return(0)
429End
430
431//testing function, not used
432Function testKeepInBounds(x1,x2,y1,y2)
433        Variable x1,x2,y1,y2
434       
435        KeepSelectionInBounds(x1,x2,y1,y2)
436        Print x1,x2,y1,y2
437        return(0)
438End
439
440Function SANS_Histogram_Pair() :  GraphMarquee
441        GetMarquee left,bottom
442        if(V_flag == 0)
443                Abort "There is no Marquee"
444        endif
445       
446        Cursor/W=SANS_Data/F/I A data 64,64
447        Cursor/M/S=2/H=1/L=0/C=(3,52428,1) A
448                               
449        // if cursor A on graph
450        // Do histogram pair
451        Variable aExists= strlen(CsrInfo(A)) > 0        // A is a name, not a string
452        if(aExists)
453                DoHistogramPair(hcsr(A),vcsr(A))
454        else
455                DoHistogramPair(64,64)
456        endif
457        return(0)
458       
459        //
460End
461// generates a histogram of the data as defined by the marquee. The longer dimension of the marquee
462// becomes the x-axis of the histogram (this may need to be changed for some odd case). Pixel range specified
463// by the marquee is inclusive, and is automatically kept in-bounds
464//
465// The counts over the (short) dimension are averaged, and plotted vs. the pixel position.
466// Pixel position is reported as Detector coordinates (1,128). Counts are whatever the current display
467// happens to be.
468//
469Function SANS_Histogram() :  GraphMarquee
470        GetMarquee left,bottom
471        if(V_flag == 0)
472                Abort "There is no Marquee"
473        endif
474//      // if cursor A on graph
475//      // Do histogram pair
476//      Variable aExists= strlen(CsrInfo(A)) > 0        // A is a name, not a string
477//      if(aExists)
478//              DoHistogramPair(hcsr(A),vcsr(A))
479//              return(0)
480//      endif
481        //
482        Variable count,x1,x2,y1,y2,xwidth,ywidth,vsX=1,xx,yy
483        x1 = V_left
484        x2 = V_right
485        y1 = V_bottom
486        y2 = V_top
487        KeepSelectionInBounds(x1,x2,y1,y2)
488        Print "x1,x2,y1,y2 (det) =",x1+1,x2+1,y1+1,y2+1
489        //determine whether to do x vs y or y vs x
490        xwidth=x2-x1
491        ywidth=y2-y1
492        if(xwidth < ywidth)
493                vsX=0           //sum and graph vs Y
494        endif
495        SVAR cur_folder=root:myGlobals:gDataDisplayType
496        WAVE data=$("root:Packages:NIST:"+cur_folder+":data")           //don't care if it's log or linear scale
497        Make/O/N=(max(xwidth,ywidth)+1) Position,AvgCounts
498        AvgCounts=0
499        //set position wave
500        if(vsX)
501                position=p+x1
502        else
503                position=p+y1
504        endif
505        //convert the position to Detector coordinates
506        position += 1
507       
508        //Compute the histogram (manually)
509        if(vsX)
510                for(xx=x1;xx<=x2;xx+=1)         //outer loop is the "x-axis"
511                        for(yy=y1;yy<=y2;yy+=1)
512                                AvgCounts[xx-x1] += data[xx][yy]
513                        endfor
514                endfor
515                AvgCounts /= (ywidth+1)
516        else
517                for(yy=y1;yy<=y2;yy+=1)
518                        for(xx=x1;xx<=x2;xx+=1)
519                                AvgCounts[yy-y1] += data[xx][yy]
520                        endfor
521                endfor
522                AvgCounts /= (xwidth+1)
523        endif
524        GetMarquee/K            //to keep from drawing the marquee on the new histo graph
525        //draw the graph, or just bring to the front with the new data
526        DoWindow/F SANS_Histo
527        if(V_Flag != 1)
528                Draw_Histo()
529        endif
530       
531        return(0)
532End
533
534//draws the histogram of the 2d data as specified by AvgCounts and Position
535//both wave are assumed to exist in the data folder. The SANS_Histogram() marquee
536//operation is responsible for creating them.
537//
538Function Draw_Histo()
539        Display /W=(197,329,567,461)/K=1 AvgCounts vs Position
540        DoWindow/C SANS_Histo
541        DoWindow/T SANS_Histo,"Histogram"
542        ModifyGraph mode=0,grid=1,mirror=2
543        ModifyGraph rgb=(21845,21845,21845)
544        ModifyGraph standoff=0
545        ModifyGraph hbFill=2
546        ModifyGraph useNegPat=1
547        ModifyGraph usePlusRGB=1
548        ModifyGraph useNegRGB=1
549        ModifyGraph hBarNegFill=2
550        ModifyGraph negRGB=(0,0,65535)
551        SetAxis/A/N=2 left
552        Label left "Counts"
553        Label bottom "Pixel (detector coordinates)"
554End
555
556//function will print marquee coordinates in axis terms, not detector terms
557//since IGOR is [0][127] and detector is (1,128)
558Function PrintMarqueeCoords() :  GraphMarquee
559        GetMarquee left,bottom
560        if(V_flag == 0)
561                Print "There is no Marquee"
562        else
563                Variable count,x1,x2,y1,y2
564                x1 = V_left
565                x2 = V_right
566                y1 = V_bottom
567                y2 = V_top
568                printf "marquee left in bottom axis terms: %g\r",round(V_left)
569                printf "marquee right in bottom axis terms: %g\r",round(V_right)
570                printf "marquee bottom in left axis terms: %g\r",round(V_bottom)
571                printf "marquee top in left axis terms: %g\r",round(V_top)
572                printf "**note that you must add 1 to each axis coordinate to get detector coordinates\r"
573               
574                KeepSelectionInBounds(x1,x2,y1,y2)
575                SVAR cur_folder=root:myGlobals:gDataDisplayType
576                count = SumCountsInBox(x1,x2,y1,y2,cur_folder)
577                Print "counts = "+ num2str(count)
578        endif
579End
580
581//
582//
583Function DoHistogramPair(xin,yin)
584        Variable xin,yin
585       
586        Variable count,x1,x2,y1,y2,xwidth,ywidth,pt1,pt2,xx,yy
587        SVAR cur_folder=root:myGlobals:gDataDisplayType
588        WAVE data=$("root:Packages:NIST:"+cur_folder+":data")           //don't care if it's log or linear scale
589       
590
591        pt1 = 1         // extent along the "long" direction of the swath
592        pt2 = 128
593               
594        Make/O/D/N=(pt2-pt1+1) PositionX,AvgCountsX
595        Make/O/D/N=(pt2-pt1+1) PositionY,AvgCountsY
596        AvgCountsX=0
597        AvgCountsY=0
598       
599        //set position wave
600        positionX=p+pt1
601        positionY=p+pt1
602        //convert the position to Detector coordinates
603        positionX += 1
604        positionY += 1
605       
606        //do the vertical, then the horizontal
607        ControlInfo/W=HistoPair setvar0
608//      Print "width = ",V_Value
609        xwidth = V_Value                //+ -
610        ywidth = V_Value
611        x1 = xin - xwidth
612        x2 = xin + xwidth
613        y1 = pt1
614        y2 = pt2
615       
616        KeepSelectionInBounds(x1,x2,y1,y2)
617//      Print "x1,x2,y1,y2 (det) =",x1+1,x2+1,y1+1,y2+1
618       
619        //Compute the histogram (manually)
620        for(yy=y1;yy<=y2;yy+=1)
621                for(xx=x1;xx<=x2;xx+=1)
622                        AvgCountsY[yy-y1] += data[xx][yy]
623                endfor
624        endfor
625        AvgCountsY /= (xwidth+1)
626
627        // now do the Y
628        y1 = yin - ywidth
629        y2 = yin + ywidth
630        x1 = pt1
631        x2 = pt2
632               
633        KeepSelectionInBounds(x1,x2,y1,y2)
634//      Print "x1,x2,y1,y2 (det) =",x1+1,x2+1,y2+1,y2+1
635        for(xx=x1;xx<=x2;xx+=1)         //outer loop is the "x-axis"
636                for(yy=y1;yy<=y2;yy+=1)
637                        AvgCountsX[xx-x1] += data[xx][yy]
638                endfor
639        endfor
640        AvgCountsX /= (ywidth+1)
641       
642        GetMarquee/K            //to keep from drawing the marquee on the new histo graph
643        //draw the graph, or just bring to the front with the new data
644        DoWindow/F HistoPair
645        if(V_Flag != 1)
646                Draw_HistoPair()
647        endif
648       
649       
650        //could draw the width lines on the graph using the normal drawing routines
651        // -- but can't draw horizontal and vertical on at the same time. MasterAngleDraw clears
652        // between drawing. Also, the lines are drawn though the beam center of the data file as
653        // loaded. Not good for beamstop alignment, since the beam center may not have been measured yet
654//      SVAR tempStr = root:myGlobals:Drawing:gDrawInfoStr
655//      String newStr = ReplaceNumberByKey("WIDTH", tempStr, xWidth, "=", ";")
656//      newStr = ReplaceNumberByKey("PHI", newStr, 0, "=", ";")
657//      String/G root:myGlobals:Drawing:gDrawInfoStr = newStr
658//      //redraw the angles
659//      MasterAngleDraw()
660               
661        // so use a pair of cursors instead (how do I easily get rid of them?) - a "done" button
662        DoWindow SANS_Data
663        if(V_flag)
664                Cursor/W=SANS_Data/K B
665                Cursor/W=SANS_Data/K C
666       
667                Cursor/W=SANS_Data/F/I B data (xin-xwidth), (yin-yWidth)
668                Cursor/W=SANS_Data/M/S=2/H=1/L=1/C=(3,52428,1) B
669        //      Cursor/W=SANS_Data/M/A=0 B
670               
671                Cursor/W=SANS_Data/F/I C data (xin+xwidth), (yin+yWidth)
672                Cursor/W=SANS_Data/M/S=2/H=1/L=1/C=(3,52428,1) C
673        //      Cursor/W=SANS_Data/M/A=0 C
674        endif   
675        return(0)
676end
677
678
679Function Draw_HistoPair()
680        PauseUpdate; Silent 1           // building window...
681        Display /W=(432.75,431.75,903,698.75)/K=2 AvgCountsX vs PositionX as "Histogram Pair"
682        AppendToGraph/L=leftY/B=bottomY AvgCountsY vs PositionY
683        DoWindow/C HistoPair
684       
685        ModifyGraph rgb(AvgCountsX)=(21845,21845,21845)
686        ModifyGraph hbFill(AvgCountsX)=2
687        ModifyGraph useNegPat(AvgCountsX)=1
688        ModifyGraph usePlusRGB(AvgCountsX)=1
689        ModifyGraph useNegRGB(AvgCountsX)=1
690        ModifyGraph hBarNegFill(AvgCountsX)=2
691        ModifyGraph negRGB(AvgCountsX)=(0,0,65535)
692        ModifyGraph grid(left)=1,grid(bottom)=1,grid(leftY)=1
693        ModifyGraph mirror(left)=2,mirror(bottom)=2,mirror(leftY)=2
694        ModifyGraph standoff(left)=0,standoff(bottom)=0,standoff(leftY)=0
695        ModifyGraph lblPos(left)=62,lblPos(bottom)=39
696        ModifyGraph freePos(leftY)=0
697        ModifyGraph freePos(bottomY)={0,leftY}
698        ModifyGraph axisEnab(left)={0,0.4}
699        ModifyGraph axisEnab(leftY)={0.6,1}
700        Label left "Counts"
701        Label bottom "Pixel (detector coordinates)"
702        SetAxis/A/N=0 left
703        TextBox/C/N=text0/X=5.0/Y=5.0 "TOP"
704        TextBox/C/N=text0_1/X=5.0/Y=67.0 "RIGHT"
705        TextBox/C/N=text0_2/X=84.0/Y=67.0 "LEFT"
706        TextBox/C/N=text0_3/X=84.0/Y=5.0 "BOTTOM"
707       
708        ControlBar 40
709//      CheckBox check0,pos={300,11},size={72,14},proc=SH_FreeCursorCheck,title="Free Cursor"
710//      CheckBox check0,value= 0
711        Button button0 title="Update",size={70,20},pos={200,9},proc=SH_RecalcButton
712        SetVariable setvar0,pos={20,11},size={120,16},title="Width (pixels)"
713        SetVariable setvar0,limits={0,64,1},value= _NUM:5,proc=SH_WidthSetVarProc
714       
715        Button button1 title="Done",size={70,20},pos={300,9},proc=SH_DoneButton
716
717EndMacro
718
719
720// not used, just for testing
721Function CursorForHistogram()
722
723        Wave w=root:Packages:NIST:RAW:RealsRead
724       
725        Cursor/W=SANS_Data/F/I A data w[16],w[17]
726        Cursor/M/S=2/H=1/L=0/C=(3,52428,1) A
727       
728End
729
730
731Function SH_FreeCursorCheck(cba) : CheckBoxControl
732        STRUCT WMCheckboxAction &cba
733
734        switch( cba.eventCode )
735                case 2: // mouse up
736                        Variable checked = cba.checked
737                       
738                                //don't move the cursor
739                                //Cursor/W=SANS_Data/F/M/S=2/H=1/L=0/C=(3,52428,1) A data
740                       
741                                Cursor/W=SANS_Data/F/I A data 64,64
742                                Cursor/M/S=2/H=1/L=0/C=(3,52428,1) A
743                               
744                        break
745        endswitch
746
747        return 0
748End
749
750Function SH_RecalcButton(ba) : ButtonControl
751        STRUCT WMButtonAction &ba
752
753        switch( ba.eventCode )
754                case 2: // mouse up
755                        // click code here
756//                      Print "at = ",hcsr(A,"SANS_Data"),vcsr(A,"SANS_Data")
757                        DoHistogramPair(hcsr(A,"SANS_Data"),vcsr(A,"SANS_Data"))
758                        break
759        endswitch
760
761        return 0
762End
763
764Function SH_DoneButton(ba) : ButtonControl
765        STRUCT WMButtonAction &ba
766
767        switch( ba.eventCode )
768                case 2: // mouse up
769                        // click code here
770                        DoWindow/K HistoPair
771                       
772                        DoWindow SANS_Data
773                        if(V_flag)
774                                Cursor/W=SANS_Data/K A
775                                Cursor/W=SANS_Data/K B
776                                Cursor/W=SANS_Data/K C
777                        endif
778                        break
779        endswitch
780
781        return 0
782End
783Function SH_WidthSetVarProc(sva) : SetVariableControl
784        STRUCT WMSetVariableAction &sva
785
786        switch( sva.eventCode )
787                case 1: // mouse up
788                case 2: // Enter key
789                case 3: // Live update
790                        Variable dval = sva.dval
791                        String sval = sva.sval
792                       
793                        DoHistogramPair(hcsr(A,"SANS_Data"),vcsr(A,"SANS_Data"))
794                       
795                        break
796        endswitch
797
798        return 0
799End
Note: See TracBrowser for help on using the repository browser.