source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Combine_1D.ipf @ 1074

Last change on this file since 1074 was 1074, checked in by srkline, 5 years ago

Important change -- re-worked the calculation of how the detector panel "gap" is treated. It is now split equally between the panels rather than assigned to one panel. Makes no difference in the q calculation, simply a philosophical change that should make the measured beam centers make a little more sense, as they will be symmetric.

Changed the appearance and function of the panel to select the "trim" values for the combined 1D data sets. Data no longer needs to be saved as ITX and re-read into the panel. Simply uses the data binning popup and the current data.

File size: 44.2 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5
6
7
8//
9// TODO:
10// x- make  the data folder list for the popup
11// x- make the data folder popup do the work of plotting
12//
13// x- (done by invoking the panel)
14//   x-make a button to show the default table, and set up dependencies to link to the graph display
15//
16// -- have an "active" data set to trim, or make duplicates for all of the data sets
17//
18// -- button to convert the points to strings that can be used and written to data files?
19// -- is this really necessary? if the save button is clicked, the strings are automatically generated
20//  -- but what if it's not? What if I do something else to send the strings to a protocol? or to a file?
21//
22// -- find a better way to be sure that the dependency does not generate errors if it is not
23//   properly killed
24//
25// -- help file
26//
27// x- larger panel
28//
29// x- error checking if the binType and the data present don't match. (test for failure)
30// -- do I really need the binType popup? How else would I know what data sets to plot/remove?
31//
32// x- table is continually duplicated
33// -- AutoPosition the windows next to each other
34// x- (different)(not ugly) color for the control bar so it's distinguishable from the regular data plot
35// x- "Done" button that kills the root:ToTrim folder (may need to kill the dependency first)
36//
37Proc V_CombineDataGraph()
38
39// this is the "initialization" step
40        NewDataFolder/O root:ToTrim
41       
42        DoWindow/F V_1D_Combine
43
44        Variable num,ii
45        String detStr
46               
47        if(V_flag==0)
48
49                Display /W=(277,526,879,1069)/N=V_1D_Combine /K=2
50
51                ControlBar 70
52                ModifyGraph cbRGB=(44000,44000,44000)
53               
54//              Button button2,pos={15,5},size={70,20},proc=V_Load_ITX_button,title="Load Data"
55//              Button button2,help={"Load an ITX file"}
56               
57//              PopupMenu popup1,pos={125,5},size={90,20},title="Data Folder"
58//              PopupMenu popup1,help={"data folder"}
59//              PopupMenu popup1,value= GetAList(4),proc=V_DataFolderPlotPop
60               
61                PopupMenu popup0,pos={15,5},size={70,20},title="Bin Type"
62                PopupMenu popup0,help={"binning type"}
63                PopupMenu popup0,value= ksBinTypeStr,proc=V_DataBinTypePlotPop
64
65                Button button3,pos={544.00,5},size={30.00,20.00},title="?"
66                Button button3,help={"help file for combining 1D data"}
67
68                CheckBox check0,pos={18.00,36.00},size={57.00,16.00},proc=V_Plot1D_LogCheckProc,title="Log Axes"
69                CheckBox check0,value= 1
70
71                Button AllQ,pos={100,36},size={70,20},proc=V_AllQ_Plot_1D_ButtonProc,title="All Q"
72                Button AllQ,help={"Show the full q-range of the dataset"}
73
74                Button button1,pos={225,36},size={100,20},proc=V_TrimWaves2StringButton,title="Wave 2 Str"
75                Button button1,help={"Convert the waves to global strings"}
76               
77//              Button button4,pos={388,36},size={90.00,20.00},title="Trim & Save"
78//              Button button4,help={"combine and save 1D data"},proc=V_SaveTrimmed_Button
79               
80                Button button0,pos={524,36},size={70,20},proc=V_DoneCombine1D_ButtonProc,title="Done"
81                Button button0,help={"Close the panel and kill the temporary folder"}
82                               
83                Legend/C/N=text0/J/X=72.00/Y=60.00
84
85        endif   
86       
87
88        //trust that the table is present? No, but don't overwrite the data in the waves
89        // unless any one of the three doesn't exist
90       
91        SetDataFolder root:Packages:NIST:VSANS:Globals:Protocols
92
93        if(exists("PanelNameW") == 0 || exists("Beg_pts") == 0 || exists("End_pts") == 0)
94                Make/O/T/N=(ItemsInList(ksPanelBinTypeList)) PanelNameW
95                Make/O/D/N=(ItemsInList(ksPanelBinTypeList)) Beg_pts
96                Make/O/D/N=(ItemsInList(ksPanelBinTypeList)) End_pts
97       
98                num = ItemsInList(ksPanelBinTypeList)
99                ii=0
100                do
101                        detStr = StringFromList(ii, ksPanelBinTypeList)
102                        Beg_pts[ii]  = NumberByKey(detStr, ksBinTrimBegDefault,"=",";")
103                        End_pts[ii] = NumberByKey(detStr, ksBinTrimEndDefault,"=",";")
104                        PanelNameW[ii] = detStr
105                        ii += 1
106                while(ii<num)
107               
108        endif
109        // now make sure that the table is present
110        DoWindow/F V_TrimPointsTable
111
112        if(V_flag==0)
113                Edit/K=0/N=V_TrimPointsTable PanelNameW,Beg_pts,End_pts         
114        endif
115       
116        // last, set up the dependency
117        Make/O/D/N=1 trimUpdate
118        trimUpdate := V_TrimTestUpdate(Beg_pts, End_pts)
119       
120       
121        SetDataFolder root:
122               
123End
124
125
126// function that is a simple dependency, and updates the trimmed waves
127// that are displayed
128//
129// does not actually modify the real data, makes a copy, and is only a visual
130//
131//
132Function V_TrimTestUpdate(Beg_pts, End_pts)
133        Wave Beg_pts,End_pts
134       
135        // trim the data displayed
136        // do this by setting the iBin values to NaN, so it won't display
137        // won't hurt to set twice...
138       
139        Wave/T panelStr = root:Packages:NIST:VSANS:Globals:Protocols:PanelNameW
140        Wave begW = root:Packages:NIST:VSANS:Globals:Protocols:Beg_pts
141        Wave endW = root:Packages:NIST:VSANS:Globals:Protocols:End_pts
142
143        // in case the dependency is still active, and the folder was killed
144        if(DataFolderExists("root:ToTrim") == 0)
145                return(0)
146        endif
147       
148//      SetDataFolder root:ToTrim
149//      ControlInfo/W=V_1D_Combine popup1
150//      String dataFldrStr = S_Value
151       
152        SVAR curDispType = root:Packages:NIST:VSANS:Globals:gCurDispType
153        String dataFldrStr = "root:Packages:NIST:VSANS:"+curDispType
154       
155        Variable num,ii,p1,p2
156        String str,detStr
157        num=numpnts(panelStr)
158       
159        for(ii=0;ii<num;ii+=1)
160                detStr = panelStr[ii]
161                Wave/Z iw = $("root:ToTrim:iBin_qxqy_"+detStr+"_trim")
162                Wave/Z iw_orig = $(dataFldrStr+":iBin_qxqy_"+detStr)
163//              Wave/Z iw = $("iBin_qxqy_"+detStr)
164//              Wave/Z ew = $("eBin_qxqy_"+detStr)
165                if(WaveExists(iw) && WaveExists(iw_orig))
166                       
167//                      DeletePoints 0,nBeg, qw,iw,ew
168                        // start fresh
169                        iw = iw_orig
170                       
171                        p1 = begW[ii]
172                        iw[0,p1-1] = NaN
173                               
174                        Variable npt
175                        npt = numpnts(iw)
176//                      DeletePoints npt-nEnd,nEnd, qw,iw,ew
177                        p2 = EndW[ii]
178                        iw[npt-p2,npt-1] = NaN
179                       
180                endif
181               
182        endfor
183       
184        SetDataFolder root:
185
186        return(0)
187End
188
189//
190// x- verify that the proper waves exist for the binning type
191//
192// x- the logic here is wrong. if the ToTrim folder is empty (As on startup)
193//  then the waves are always missing - and the function returns an error - every time
194//
195// now works with the "current" data that is displayed, rather than relying on
196// a lot of user input regarding the details of the saved data
197//
198Function V_DataBinTypePlotPop(ctrlName,popNum,popStr) : PopupMenuControl
199        String ctrlName
200        Variable popNum // which item is currently selected (1-based)
201        String popStr           // contents of current popup item as string
202
203
204        String str,winStr="V_1D_Combine"
205        Variable binType,num,ii,err
206
207        binType = V_BinTypeStr2Num(popStr)
208       
209       
210        //  x- need to update this to make sure that the data waves are present before plotting. This
211        //    currently looks in the ToTrim folder, but the binning could be wrong in the data folder
212        //    and will be an error...
213       
214        //dataType now needs to be the full path to the folder
215        // Plot the "real" data. data copy to trim will be plotted later
216        //
217        SVAR dispType = root:Packages:NIST:VSANS:Globals:gCurDispType
218
219
220// dispatch based on the string, not on the number of selection in the pop string
221        V_QBinAllPanels_Circular(dispType,binType)
222
223        String workTypeStr
224        workTypeStr = "root:Packages:NIST:VSANS:"+dispType
225       
226
227//      dataType = "root:"+popStr
228//     
229//      //remove EVERYTHING from the graph, no matter what
230        String type,list,item
231//      list = TraceNameList(winStr,";",1)
232//      for(ii=0;ii<ItemsInList(list);ii+=1)
233//              item = StringFromList(ii, list, ";")
234////            CheckDisplayed/W=$winStr $(item)
235////            if(V_flag==1)
236//                      RemoveFromGraph/Z/W=$winStr $(item)
237////            endif
238//      endfor 
239//     
240       
241        sprintf str,"(\"%s\",%d,\"%s\")",workTypeStr,binType,winStr
242
243        Execute ("V_Back_IQ_Graph"+str)
244        Execute ("V_Middle_IQ_Graph"+str)
245        Execute ("V_Front_IQ_Graph"+str)
246
247        ModifyGraph marker=8,opaque=1,msize=3           //make the traces open white circles
248
249
250        NewDataFolder/O root:ToTrim
251       
252        //remove all of the "toTrim" data from the graph, if it's there
253        SetDataFolder root:ToTrim
254        for(ii=0;ii<ItemsInList(ksPanelBinTypeList);ii+=1)
255                type = StringFromList(ii, ksPanelBinTypeList, ";")
256                CheckDisplayed/W=$winStr $("iBin_qxqy_"+type+"_trim")
257                if(V_flag==1)
258                        RemoveFromGraph/W=$winStr $("iBin_qxqy_"+type+"_trim")
259                endif
260        endfor 
261        SetDataFolder root:
262
263
264        //then kill the data folder, so it can be duplicated
265       
266//
267//      // duplicate all of the data into the new folder
268        SetDataFolder $workTypeStr
269        list = WaveList("*",";","")             //must be in the correct data folder
270        SetDataFolder root:
271//      Print list     
272        num = ItemsInList(list)
273        for(ii=0;ii<num;ii+=1)
274                str = StringFromList(ii,list)
275                Duplicate/O $(workTypeStr+":"+str), $("root:ToTrim:"+str+"_trim")
276        endfor
277       
278//      // be sure that the data is present in the ToTrim folder before trying to plot
279//      err = V_TrimWavesExist(binType)
280//      if(err)
281//              DoAlert 0,"wrong bin type selected"
282//              return(0)
283//      endif
284       
285       
286        // plot the linked data
287        sprintf str,"(\"%s\",%d,\"%s\")","root:ToTrim",binType,winStr
288
289        Execute ("V_Back_IQ_Graph_trim"+str)
290        Execute ("V_Middle_IQ_Graph_trim"+str)
291        Execute ("V_Front_IQ_Graph_trim"+str)
292        // and link the data to the table with a dependency?
293//      done in the panel macro?
294       
295        // last, force the dependency to update so that the trimmed points are shown
296        Wave w = root:Packages:NIST:VSANS:Globals:Protocols:Beg_pts
297        w[0] += 1
298        w[0] -= 1
299       
300       
301        return(0)       
302End
303
304
305
306//
307// x- verify that the proper waves exist for the binning type
308//
309// x- the logic here is wrong. if the ToTrim folder is empty (As on startup)
310//  then the waves are always missing - and the function returns an error - every time
311//
312// currently unused, in favor of using the current data rather than saved itx data
313//
314Function V_DataFolderPlotPop(ctrlName,popNum,popStr) : PopupMenuControl
315        String ctrlName
316        Variable popNum // which item is currently selected (1-based)
317        String popStr           // contents of current popup item as string
318
319
320        String str,winStr="V_1D_Combine",dataType
321        Variable binType,num,ii
322        ControlInfo popup0
323        binType = V_BinTypeStr2Num(S_Value)
324       
325       
326        //  x- need to update this to make sure that the data waves are present before plotting. This
327        //    currently looks in the ToTrim folder, but the binning could be wrong in the data folder
328        //    and will be an error...
329       
330        // be sure that the data is present in the ToTrim folder before trying to plot
331        Variable err = V_itxWavesExist(popStr,binType)
332        if(err)
333                DoAlert 0,"wrong bin type selected"
334                return(0)
335        endif
336       
337       
338        //dataType now needs to be the full path to the folder
339        // Plot the "real" data. data copy to trim will be plotted later
340        //
341        dataType = "root:"+popStr
342       
343        //remove EVERYTHING from the graph, no matter what
344        String type,list,item
345        list = TraceNameList(winStr,";",1)
346        for(ii=0;ii<ItemsInList(list);ii+=1)
347                item = StringFromList(ii, list, ";")
348//              CheckDisplayed/W=$winStr $(item)
349//              if(V_flag==1)
350                        RemoveFromGraph/Z/W=$winStr $(item)
351//              endif
352        endfor 
353       
354       
355        sprintf str,"(\"%s\",%d,\"%s\")",dataType,binType,winStr
356
357        Execute ("V_Back_IQ_Graph"+str)
358        Execute ("V_Middle_IQ_Graph"+str)
359        Execute ("V_Front_IQ_Graph"+str)
360
361        ModifyGraph marker=8,opaque=1,msize=3           //make the traces open white circles
362
363
364        NewDataFolder/O root:ToTrim
365       
366        //remove all of the "toTrim" data from the graph, if it's there
367        SetDataFolder root:ToTrim
368        for(ii=0;ii<ItemsInList(ksPanelBinTypeList);ii+=1)
369                type = StringFromList(ii, ksPanelBinTypeList, ";")
370                CheckDisplayed/W=$winStr $("iBin_qxqy_"+type+"_trim")
371                if(V_flag==1)
372                        RemoveFromGraph/W=$winStr $("iBin_qxqy_"+type+"_trim")
373                endif
374        endfor 
375        SetDataFolder root:
376
377
378        //then kill the data folder, so it can be duplicated
379       
380//
381//      // duplicate all of the data into the new folder
382        SetDataFolder $dataType
383        list = WaveList("*",";","")             //must be in the correct data folder
384        SetDataFolder root:
385//      Print list     
386        num = ItemsInList(list)
387        for(ii=0;ii<num;ii+=1)
388                str = StringFromList(ii,list)
389                Duplicate/O $(dataType+":"+str), $("root:ToTrim:"+str+"_trim")
390        endfor
391       
392        // be sure that the data is present in the ToTrim folder before trying to plot
393        err = V_TrimWavesExist(binType)
394        if(err)
395                DoAlert 0,"wrong bin type selected"
396                return(0)
397        endif
398       
399       
400        // plot the linked data
401        sprintf str,"(\"%s\",%d,\"%s\")","root:ToTrim",binType,winStr
402
403        Execute ("V_Back_IQ_Graph_trim"+str)
404        Execute ("V_Middle_IQ_Graph_trim"+str)
405        Execute ("V_Front_IQ_Graph_trim"+str)
406        // and link the data to the table with a dependency?
407//      done in the panel macro?
408       
409        // last, force the dependency to update so that the trimmed points are shown
410        Wave w = root:Packages:NIST:VSANS:Globals:Protocols:Beg_pts
411        w[0] += 1
412        w[0] -= 1
413       
414       
415        return(0)       
416End
417
418
419
420// kill the dependency,
421// kill the panel, then the associated ToTrim folder
422// do not kill the beg/end waves
423//
424Function V_DoneCombine1D_ButtonProc(ctrlName) : ButtonControl
425        String ctrlName
426       
427        Wave trimUpdate = root:Packages:NIST:VSANS:Globals:Protocols:trimUpdate
428        trimUpdate = 1          //kills the dependency
429        DoWindow/K V_1D_Combine
430       
431        KillDataFolder/Z root:ToTrim
432       
433        return(0)
434End
435
436// TODO
437// -- verify that this works for all binning cases
438// -- see V_Trim1DDataStr to see if they can be combined
439//
440Function V_SaveTrimmed_Button(ctrlName) : ButtonControl
441        String ctrlName
442       
443        String detListStr,dataType,str
444        Variable bintype,num,ii
445
446        ControlInfo popup0
447        binType = V_BinTypeStr2Num(S_Value)
448       
449       
450        if(binType == 1)
451                detListStr = ksBinType1
452        endif
453        if(binType == 2)
454                detListStr = ksBinType2
455        endif
456        if(binType == 3)
457                detListStr = ksBinType3
458        endif
459        if(binType == 4)
460                detListStr = ksBinType4
461        endif
462        if(strlen(detListStr)==0)
463                return(0)
464        endif
465
466// set the global strings
467        V_TrimWaves2String()            //in case the button wasn't clicked
468        SVAR gBegPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gBegPtsStr
469        SVAR gEndPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gEndPtsStr
470
471// get a fresh copy of the data
472// duplicate all of the data into the new folder
473        ControlInfo popup1
474        dataType = "root:"+S_Value
475
476        SetDataFolder $dataType
477        String list = WaveList("*",";","")              //must be in the correct data folder
478        SetDataFolder root:
479//      Print list     
480        num = ItemsInList(list)
481        for(ii=0;ii<num;ii+=1)
482                str = StringFromList(ii,list)
483                Duplicate/O $(dataType+":"+str), $("root:ToTrim:"+str+"_trim")
484        endfor
485
486       
487// trim each data set
488        Variable nBeg,nEnd,npt
489        String detstr
490       
491        SetDataFolder root:ToTrim
492        num = ItemsInList(detListStr)
493        for(ii=0;ii<num;ii+=1)
494                detStr = StringFromList(ii, detListStr)
495                nBeg = NumberByKey(detStr, gBegPtsStr,"=",";")
496                nEnd = NumberByKey(detStr, gEndPtsStr,"=",";")
497               
498//              V_TrimOneSet(folderStr,detStr,nBeg,nEnd)
499                Wave/Z qw = $("qBin_qxqy_"+detStr+"_trim")
500                Wave/Z iw = $("iBin_qxqy_"+detStr+"_trim")
501                Wave/Z ew = $("eBin_qxqy_"+detStr+"_trim")
502
503                DeletePoints 0,nBeg, qw,iw,ew
504
505                npt = numpnts(qw)
506                DeletePoints npt-nEnd,nEnd, qw,iw,ew
507//             
508        endfor
509
510
511// remove Q=0 from "B" if it's present
512        SetDataFolder root:ToTrim
513        WAVE/Z qBin = qBin_qxqy_B_trim
514        WAVE/Z iBin = iBin_qxqy_B_trim
515        WAVE/Z eBin = eBin_qxqy_B_trim
516//      WAVE/Z nBin = nBin_qxqy_B_trim
517//      WAVE/Z iBin2 = iBin2_qxqy_B_trim
518
519        if(qBin[0] == 0)
520                DeletePoints 0, 1, qBin,iBin,eBin//,nBin,iBin2
521        endif
522
523       
524// concatenate
525        V_1DConcatenate("root:","ToTrim","_trim",binType)
526
527// sort the waves - concatenation creates tmp_q, tmp_i, tmp_s
528// so this call will work (doesn't need the "_trim" tag)
529        V_TmpSort1D("root:","ToTrim")
530
531// write out the data to disk
532
533        Execute "V_GetNameForSave()"
534        SVAR newName = root:saveName
535        String saveName = newName
536
537        //will write out the tmp_q, tmp_i, tmp_s waves
538        V_Write1DData("root:","ToTrim",saveName)                //don't pass the full path, just the name
539
540       
541// put a fresh copy of the data back into the folder since the data was actually trimmed
542// duplicate all of the data into the new folder
543        ControlInfo popup1
544        dataType = "root:"+S_Value
545
546        SetDataFolder $dataType
547        list = WaveList("*",";","")             //must be in the correct data folder
548        SetDataFolder root:
549//      Print list     
550        num = ItemsInList(list)
551        for(ii=0;ii<num;ii+=1)
552                str = StringFromList(ii,list)
553                Duplicate/O $(dataType+":"+str), $("root:ToTrim:"+str+"_trim")
554        endfor
555
556
557        SetDataFolder root:
558       
559        return(0)
560End
561
562
563
564//
565// dialog to select and load an itx format data file
566//
567Function V_Load_ITX_Button(ctrlName) : ButtonControl
568        String ctrlName
569       
570        Execute "V_Load_Data_ITX()"
571       
572        return(0)
573End
574
575
576// TODO
577// -- document
578Function V_TrimWaves2StringButton(ctrlName) : ButtonControl
579        String ctrlName
580       
581        V_TrimWaves2String()
582
583        return(0)
584End
585
586// for each of the binning types, be sure that the corresponding waves in the
587// root:ToTrim folder actually do exist.
588// return 0 for OK, 1 if error
589Function V_TrimWavesExist(binType)
590        Variable binType
591       
592        String binStr="",str
593        Variable num,ii
594       
595        if(binType == 1)
596                binStr = ksBinType1
597        endif
598        if(binType == 2)
599                binStr = ksBinType2
600        endif
601        if(binType == 3)
602                binStr = ksBinType3
603        endif
604        if(binType == 4)
605                binStr = ksBinType4
606        endif
607       
608        num = ItemsInList(binStr)
609        for(ii=0;ii<num;ii+=1)
610                str = StringFromList(ii,binStr)
611                if(exists("root:ToTrim:iBin_qxqy_"+Str+"_trim") == 0)           // not in use = error
612                        return(1)
613                endif
614        endfor
615       
616        return(0)               //everything checked out OK, no error
617
618end
619
620// for each of the binning types, be sure that the corresponding waves in the
621// root:ToTrim folder actually do exist.
622// return 0 for OK, 1 if error
623Function V_itxWavesExist(folderStr,binType)
624        String folderStr
625        Variable binType
626       
627        String binStr="",str
628        Variable num,ii
629       
630        if(binType == 1)
631                binStr = ksBinType1
632        endif
633        if(binType == 2)
634                binStr = ksBinType2
635        endif
636        if(binType == 3)
637                binStr = ksBinType3
638        endif
639        if(binType == 4)
640                binStr = ksBinType4
641        endif
642       
643        num = ItemsInList(binStr)
644        for(ii=0;ii<num;ii+=1)
645                str = StringFromList(ii,binStr)
646                if(exists("root:"+folderStr+":iBin_qxqy_"+Str) == 0)            // not in use = error
647                        return(1)
648                endif
649        endfor
650       
651        return(0)               //everything checked out OK, no error
652
653end
654
655
656
657//
658// take the waves, and convert to strings that can be added to the protocol
659//
660//
661// x- get the variables out of root:, and move it to Protocols
662// x- get the waves out of root:, and move it to Protocols
663// x- be sure that the variables are initialized (done in main initialization
664// x- link this to the panel?
665//
666Function V_TrimWaves2String()
667
668
669        SVAR gBegPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gBegPtsStr
670        SVAR gEndPtsStr=root:Packages:NIST:VSANS:Globals:Protocols:gEndPtsStr
671
672        Wave/T PanelNameW = root:Packages:NIST:VSANS:Globals:Protocols:PanelNameW
673        Wave Beg_pts = root:Packages:NIST:VSANS:Globals:Protocols:Beg_pts
674        Wave End_pts = root:Packages:NIST:VSANS:Globals:Protocols:End_pts
675       
676// ksPanelBinTypeList = "B;FT;FB;FL;FR;MT;MB;ML;MR;FTB;FLR;MTB;MLR;FLRTB;MLRTB;"
677// ksBinTrimBegDefault = "B=5;FT=6;FB=6;FL=6;FR=6;MT=6;MB=6;ML=6;MR=6;FTB=7;FLR=7;MTB=7;MLR=7;FLRTB=8;MLRTB=8;"
678// ksBinTrimEndDefault
679
680        // wipe out the "old" global strings
681        gBegPtsStr = ksBinTrimBegDefault
682        gEndPtsStr = ksBinTrimEndDefault
683
684        Variable num, ii,nBeg,nEnd
685        String item,panelStr
686       
687        num = numpnts(PanelNameW)
688        for(ii=0;ii<num;ii+=1)
689                panelStr = PanelNameW[ii]
690                gBegPtsStr = ReplaceNumberByKey(panelStr, gBegPtsStr, Beg_pts[ii],"=",";")
691                gEndPtsStr = ReplaceNumberByKey(panelStr, gEndPtsStr, End_pts[ii],"=",";")
692        endfor
693
694        return(0)
695End
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717//////////////// Below is unused -- it was started, but seems like the wrong approach,
718//////////////// so I have abandoned it for now
719//
720//
721// ((this approach using USANS ideas has temporarily been abandoned...))
722//
723// Preliminary routines for adjusting, masking, and combining 1D VSANS data sets.
724//
725// ideas taken from USANS to mask data sets
726// avoiding duplication of NSORT, since autoscale is not in favor, and there may be anywhere
727//   from 3 to 9 data sets to combine
728//
729// masking waves are saved in the "Combine_1D" folder, BUT the masking may eventually be part
730//  of the data reduction protocol - and anything in work folders will be lost
731//
732
733
734////////////////
735// TODO:
736// x- add a popup to the load tab to set the work folder
737// x- add this file to the Includes list and to the SVN folder
738// -- add button (mask tab) to save mask
739// -- add button (mask tab) to recall mask
740// -- think of ways to run through the files batchwise (instead of adding this to the protocol)
741// -- link the main entry procedure to the main panel
742//
743// -- when do I concatenate the data sets?
744// ---- do I add a concatenate button to the Load tab, then this single set is the
745//    starting point for the MASK tab
746// ---- the Load Data button could then be a loader for a single file, which is then the "concatenated"
747//     starting point...
748//
749// x- make the graph larger for easier viewing of the data
750// -- increase the size of the tab control, rearrange the other controls
751//
752// -- how do I incorporate the rescaling?
753//
754// -- error bars on the graph
755// x- legend on the graph
756//
757// x- define a new folder for all of this -- NOT the protocol folder
758// x- define a string constant with this path
759//
760// -- button to mask based on relative error threshold for each data point. may be a good startng point for
761//    masking
762//
763// -- remove the mask by relative error button - this is not really a good idea.
764//
765//
766//
767//
768//StrConstant ksCombine1DFolder = "root:Packages:NIST:VSANS:Globals:Combine_1D"
769//
770//// main entry routine
771//Proc V_Combine_1D()
772//
773//      //check for the correct folder, initialize if necessary
774//      //
775//      if(DataFolderExists(ksCombine1DFolder) == 0)
776//              Execute "V_Init_Combine_1D()"
777//      endif
778//     
779//      SetDataFolder root:
780//     
781//      DoWindow/F V_Combine_1D_Graph
782//      if(V_flag==0)
783//              Execute "V_Combine_1D_Graph()"
784//      endif
785//End
786//
787//Proc V_Init_Combine_1D()
788//
789//      //set up the folder(s) needed
790//      NewDataFolder/O $(ksCombine1DFolder)
791//     
792//      SetDataFolder $(ksCombine1DFolder)
793//     
794//      String/G gCurFile=""
795//      String/G gStr1=""
796//      Variable/G gFreshMask=1
797//      Variable/G gNq=0
798//     
799//      SetDataFolder root:
800//End
801//
802//
803//////
804////
805////
806//Proc V_Combine_1D_Graph()
807//
808//      PauseUpdate; Silent 1           // building window...
809//      Display /W=(699,45,1328,779) /K=1
810//      ModifyGraph cbRGB=(51664,44236,58982)
811//      ModifyGraph tickUnit=1
812//      DoWindow/C V_Combine_1D_Graph
813//      ControlBar 160
814//      // break into tabs
815//      TabControl C1D_Tab,pos={5,3},size={392,128},proc=C1D_TabProc
816//      TabControl C1D_Tab,labelBack=(49151,49152,65535),tabLabel(0)="Load"
817//      TabControl C1D_Tab,tabLabel(1)="Mask",tabLabel(2)="Rescale",value=0
818//     
819//      //always visible - revert and save
820//      //maybe the wrong place here?
821//      Button C1DControlA,pos={225,135},size={80,20},proc=C1D_RevertButtonProc,title="Revert"
822//      Button C1DControlA,help={"Revert the data to its original state and start over"}
823//      Button C1DControlB,pos={325,135},size={50,20},proc=C1D_SaveButtonProc,title="Save"
824//      Button C1DControlB,help={"Save the masked and scaled data set"}
825//      Button C1DControlC,pos={25,135},size={50,20},proc=C1D_HelpButtonProc,title="Help"
826//      Button C1DControlC,help={"Show the help file for combining VSANS data sets"}
827//     
828//      // add the controls to each tab ---- all names start with "C1DControl_"
829//
830//      //tab(0) Load - initially visible
831//      Button C1DControl_0a,pos={23,39},size={80,20},proc=C1D_LoadButtonProc,title="Load Data"
832//      Button C1DControl_0a,help={"Load slit-smeared USANS data = \".cor\" files"}
833//      CheckBox C1DControl_0b,pos={26,74},size={80,14},proc=C1D_LoadCheckProc,title="Log Axes?"
834//      CheckBox C1DControl_0b,help={"Toggle Log/Lin Q display"},value= 1
835//      TitleBox C1DControl_0c,pos={120,37},size={104,19},font="Courier",fSize=10
836//      TitleBox C1DControl_0c,variable= $(ksCombine1DFolder+":gStr1")
837//      PopupMenu C1DControl_0d,pos={120,75},size={71,20},title="Bin Type"
838//      PopupMenu C1DControl_0d,help={"This popup selects how the y-axis will be linearized based on the chosen data"}
839//      PopupMenu C1DControl_0d,value= ksBinTypeStr
840//      PopupMenu C1DControl_0d,mode=1,proc=V_CombineModePopup
841//      PopupMenu C1DControl_0e,pos={120,100},size={109,20},title="Data Source"
842//      PopupMenu C1DControl_0e,mode=1,popvalue="RAW",value= #"\"RAW;SAM;EMP;BGD;COR;ABS;\""           
843//      Button C1DControl_0f,pos={200,39},size={120,20},proc=C1D_ConcatButtonProc,title="Concatenate"
844//      Button C1DControl_0f,help={"Load slit-smeared USANS data = \".cor\" files"}
845//
846//     
847//      //tab(1) Mask
848//      Button C1DControl_1a,pos={20,35},size={90,20},proc=C1D_MyMaskProc,title="Mask Point"            //bMask
849//      Button C1DControl_1a,help={"Toggles the masking of the selected data point"}
850//      Button C1DControl_1a,disable=1
851//      Button C1DControl_1b,pos={20,65},size={140,20},proc=C1D_MaskGTCursor,title="Mask Q >= Cursor"           //bMask
852//      Button C1DControl_1b,help={"Toggles the masking of all q-values GREATER than the current cursor location"}
853//      Button C1DControl_1b,disable=1
854//      Button C1DControl_1c,pos={20,95},size={140,20},proc=C1D_MaskLTCursor,title="Mask Q <= Cursor"           //bMask
855//      Button C1DControl_1c,help={"Toggles the masking of all q-values LESS than the current cursor location"}
856//      Button C1DControl_1c,disable=1
857//      Button C1DControl_1d,pos={180,35},size={90,20},proc=C1D_ClearMaskProc,title="Clear Mask"                //bMask
858//      Button C1DControl_1d,help={"Clears all mask points"}
859//      Button C1DControl_1d,disable=1
860//      Button C1DControl_1e,pos={180,65},size={90,20},proc=C1D_MaskPercent,title="Percent Mask"                //bMask
861//      Button C1DControl_1e,help={"Clears all mask points"}
862//      Button C1DControl_1e,disable=1
863//     
864//     
865////    Button C1DControl_1b,pos={144,66},size={110,20},proc=C1D_MaskDoneButton,title="Done Masking"
866////    Button C1DControl_1b,disable=1
867//     
868////    //tab(2) Rescale
869//      Button C1DControl_2a,pos={31,42},size={90,20},proc=C1D_ExtrapolateButtonProc,title="Extrapolate"
870//      Button C1DControl_2a,help={"Extrapolate the high-q region with a power-law"}
871//      Button C1DControl_2a,disable=1
872//      SetVariable C1DControl_2b,pos={31,70},size={100,15},title="# of points"
873//      SetVariable C1DControl_2b,help={"Set the number of points for the power-law extrapolation"}
874//      SetVariable C1DControl_2b,limits={5,100,1},value=_NUM:123
875//      SetVariable C1DControl_2b,disable=1
876//      CheckBox C1DControl_2c,pos={157,45},size={105,14},proc=C1D_ExtrapolationCheckProc,title="Show Extrapolation"
877//      CheckBox C1DControl_2c,help={"Show or hide the high q extrapolation"},value= 1
878//      CheckBox C1DControl_2c,disable=1
879//      SetVariable C1DControl_2d,pos={31,96},size={150,15},title="Power Law Exponent"
880//      SetVariable C1DControl_2d,help={"Power Law exponent from the fit = the DESMEARED slope - override as needed"}
881//      SetVariable C1DControl_2d format="%5.2f"
882//      SetVariable C1DControl_2d,limits={-inf,inf,0},value=_NUM:123
883//      SetVariable C1DControl_2d,disable=1
884//     
885//      Legend/C/N=text0/J/X=72.00/Y=60.00
886//
887//     
888//      SetDataFolder root:
889//EndMacro
890//
891////
892//// recalculate the I(q) binning. no need to adjust model function or views
893//// just rebin
894////
895//// see V_BinningModePopup() in V_DataPlotting.ipf for a duplicate verison of this function
896//Function V_CombineModePopup(ctrlName,popNum,popStr) : PopupMenuControl
897//      String ctrlName
898//      Variable popNum // which item is currently selected (1-based)
899//      String popStr           // contents of current popup item as string
900//
901//// TODO
902//// x- replace the type with selection from the panel - don't use the current display type
903//      ControlInfo C1DControl_0e
904//      String type = S_Value
905//
906//      SVAR gStr1 = $(ksCombine1DFolder+":gStr1")
907//      gStr1 = type
908//     
909//     
910//      V_QBinAllPanels(type,popNum)
911//
912//
913//      String str,winStr="V_Combine_1D_Graph"
914//      sprintf str,"(\"%s\",%d,\"%s\")",type,popNum,winStr
915//
916//// TODO:
917//// x- replace these calls -- they work with the 1d plot, not this panel. I want them to do basically the same
918////    exact things, but with a different target window
919////  *** these calls now take the target window as a parameter - so that there is only one version
920//      Execute ("V_Back_IQ_Graph"+str)
921//      Execute ("V_Middle_IQ_Graph"+str)
922//      Execute ("V_Front_IQ_Graph"+str)
923//             
924//     
925//      return(0)       
926//End
927//
928//
929//// function to control the drawing of buttons in the TabControl on the main panel
930//// Naming scheme for the buttons MUST be strictly adhered to... else buttons will
931//// appear in odd places...
932//// all buttons are named C1DControl_NA where N is the tab number and A is the letter denoting
933//// the button's position on that particular tab.
934//// in this way, buttons will always be drawn correctly :-)
935////
936//Function C1D_TabProc(ctrlName,tab) //: TabControl
937//      String ctrlName
938//      Variable tab
939//
940//      String ctrlList = ControlNameList("",";"),item="",nameStr=""
941//      Variable num = ItemsinList(ctrlList,";"),ii,onTab
942//      for(ii=0;ii<num;ii+=1)
943//              //items all start w/"C1DControl_"               //11 characters
944//              item=StringFromList(ii, ctrlList ,";")
945//              nameStr=item[0,10]
946//              if(cmpstr(nameStr,"C1DControl_")==0)
947//                      onTab = str2num(item[11])                       //12th is a number
948//                      ControlInfo $item
949//                      switch(abs(V_flag))     
950//                              case 1:
951//                                      Button $item,disable=(tab!=onTab)
952//                                      break
953//                              case 2:
954//                                      CheckBox $item,disable=(tab!=onTab)
955//                                      break
956//                              case 5:
957//                                      SetVariable $item,disable=(tab!=onTab)
958//                                      break
959//                              case 10:       
960//                                      TitleBox $item,disable=(tab!=onTab)
961//                                      break
962//                              case 4:
963//                                      ValDisplay $item,disable=(tab!=onTab)
964//                                      break
965//                              case 3:
966//                                      PopupMenu $item,disable=(tab!=onTab)
967//                                      break
968//                              // add more items to the switch if different control types are used
969//                      endswitch
970//                     
971//              endif
972//      endfor
973//     
974//      // remove the mask if I go back to the data?
975//      if(tab==0)
976//              RemoveMask()
977////            RemoveConcatenated()
978//      endif
979//     
980//      // masking
981//      if(tab==1)
982//              C1D_ClearMaskProc("")           //starts with a blank mask
983//              C1D_MyMaskProc("")              //start masking if you click on the tab
984//      else
985//              C1D_MaskDoneButton("")          //masking is done if you click off the tab
986//      endif
987//     
988//      // rescaling
989//      if(tab == 2)
990//      // TODO
991//      // -- fill this in
992//      // -- this is still in the thought process at this point
993//     
994//// do rescaling of the different sections of the data set
995//             
996//      endif
997//     
998//      return 0
999//End
1000//
1001//
1002//Proc AppendConcatenated()
1003//
1004//      if( strsearch(TraceNameList("V_Combine_1D_Graph", "", 1),"I_exp_orig",0,2) == -1)                       //Igor 5
1005//              SetDataFolder $(ksCombine1DFolder)
1006//              AppendToGraph/W=V_Combine_1D_Graph I_exp_orig vs Q_exp_orig
1007//              ModifyGraph mode(I_exp_orig)=3,marker(I_exp_orig)=19,msize(I_exp_orig)=2,opaque(I_exp_orig)=1
1008//              ModifyGraph rgb(I_exp_orig)=(0,0,0)
1009//             
1010//              ModifyGraph tickUnit=1,log=1
1011//              Modifygraph grid=1,mirror=2
1012//
1013//              ErrorBars/T=0 I_exp_orig Y,wave=(S_exp_orig,S_exp_orig)
1014//             
1015//              setdatafolder root:
1016//      endif
1017//end
1018//
1019//Function RemoveConcatenated()
1020//
1021//      SetDataFolder $(ksCombine1DFolder)
1022//      RemoveFromGraph/W=V_Combine_1D_Graph/Z I_exp_orig
1023//      setdatafolder root:
1024//end
1025//
1026//Proc AppendMask()
1027//
1028//      if( strsearch(TraceNameList("V_Combine_1D_Graph", "", 1),"MaskData",0,2) == -1)                 //Igor 5
1029//              SetDataFolder $(ksCombine1DFolder)
1030//              AppendToGraph/W=V_Combine_1D_Graph MaskData vs Q_exp_orig
1031//              ModifyGraph mode(MaskData)=3,marker(MaskData)=8,msize(MaskData)=2.5,opaque(MaskData)=1
1032//              ModifyGraph rgb(MaskData)=(65535,16385,16385)
1033//             
1034//              setdatafolder root:
1035//      endif
1036//end
1037//
1038//
1039//
1040//Function RemoveMask()
1041//
1042//      SetDataFolder $(ksCombine1DFolder)
1043//      RemoveFromGraph/W=V_Combine_1D_Graph/Z MaskData
1044//      setdatafolder root:
1045//end
1046//
1047//
1048//// concatenate the data, and replace the multiple data sets with the concatenated set
1049//// - then you can proceed to the mask tab
1050////
1051//Function C1D_ConcatButtonProc(ctrlName) : ButtonControl
1052//      String ctrlName
1053//
1054//
1055//      ControlInfo C1DControl_0e
1056//      String folderStr = S_Value
1057//
1058//      SVAR gStr1 = $(ksCombine1DFolder+":gStr1")
1059//      gStr1 = folderStr
1060//
1061//
1062//      ControlInfo C1DControl_0d
1063//      Variable binType = V_BinTypeStr2Num(S_Value)
1064//     
1065//      V_1DConcatenate("root:Packages:NIST:VSANS:",folderStr,"",binType)
1066//
1067//// sort the data set
1068//      V_TmpSort1D("root:Packages:NIST:VSANS:",folderStr)
1069//     
1070//// now copy the concatenated data over to the combine folder 
1071//      Duplicate/O $("root:Packages:NIST:VSANS:"+folderStr+":tmp_q") $(ksCombine1DFolder+":Q_exp")             
1072//      Duplicate/O $("root:Packages:NIST:VSANS:"+folderStr+":tmp_i") $(ksCombine1DFolder+":I_exp")             
1073//      Duplicate/O $("root:Packages:NIST:VSANS:"+folderStr+":tmp_s") $(ksCombine1DFolder+":S_exp")     
1074//      wave Q_exp = $(ksCombine1DFolder+":Q_exp")
1075//      Wave I_exp = $(ksCombine1DFolder+":I_exp")
1076//      Wave S_exp = $(ksCombine1DFolder+":S_exp")
1077//     
1078//
1079////   
1080//      Duplicate/O $(ksCombine1DFolder+":Q_exp") $(ksCombine1DFolder+":Q_exp_orig")
1081//      Duplicate/O $(ksCombine1DFolder+":I_exp") $(ksCombine1DFolder+":I_exp_orig")
1082//      Duplicate/O $(ksCombine1DFolder+":S_exp") $(ksCombine1DFolder+":S_exp_orig")
1083//      wave I_exp_orig = $(ksCombine1DFolder+":I_exp_orig")
1084//     
1085//      Variable nq = numpnts($(ksCombine1DFolder+":Q_exp"))
1086////   
1087//
1088////    // append the (blank) wave note to the intensity wave
1089////    Note I_exp,"BOX=0;SPLINE=0;"
1090////    Note I_exp_orig,"BOX=0;SPLINE=0;"
1091////   
1092////    //add data to the graph
1093//      Execute "AppendConcatenated()" 
1094//     
1095//      // TODO:
1096//      // -- do I clear off the old data here, or somewhere else?
1097//      // clear off the old data from the individual panels
1098//      // use ClearAllIQIfDisplayed()
1099//      ClearIQIfDisplayed_AllBin(folderStr,"V_Combine_1D_Graph")
1100//
1101//      RemoveMask()
1102//     
1103//      return(0)
1104//End
1105//
1106//// step (1) - get the data from a WORK folder, and plot it
1107//// clear out all of the "old" waves, remove them from the graph first
1108////
1109//// ??produces Q_exp, I_exp, S_exp waves (and originals "_orig")
1110//// add a dummy wave note that can be changed on later steps
1111////
1112//Function C1D_LoadButtonProc(ctrlName) : ButtonControl
1113//      String ctrlName
1114//
1115//
1116//      String qStr,iStr,sStr,sqStr
1117//      Variable nq,dqv,numBad,val
1118//     
1119//      // remove any of the old traces on the graph and delete the waves and reset the global strings
1120//      CleanUpJunk()
1121//     
1122//      SetDataFolder root:
1123//     
1124//      // go get the new data
1125//      Execute "A_LoadOneDDataWithName(\"\",0)"
1126//
1127//// TODO:     
1128//      // x-Missing something here from the loader - go back to the LakeDesmearing ipf
1129//      SVAR fname = root:Packages:NIST:gLastFileName           //this is the 1D file loaded
1130//
1131////   
1132//      qStr = CleanupName((fName + "_q"),0)            //the q-wave
1133//      iStr = CleanupName((fName + "_i"),0)            //the i-wave
1134//      sStr = CleanupName((fName + "_s"),0)            //the s-wave
1135////    sqStr = CleanupName((fName + "sq"),0)           //the sq-wave
1136////
1137//      String DFStr= CleanupName(fname,0)
1138////   
1139//      Duplicate/O $("root:"+DFStr+":"+qStr) $(ksCombine1DFolder+":Q_exp")             
1140//      Duplicate/O $("root:"+DFStr+":"+iStr) $(ksCombine1DFolder+":I_exp")             
1141//      Duplicate/O $("root:"+DFStr+":"+sStr) $(ksCombine1DFolder+":S_exp")     
1142//      wave Q_exp = $(ksCombine1DFolder+":Q_exp")
1143//      Wave I_exp = $(ksCombine1DFolder+":I_exp")
1144//      Wave S_exp = $(ksCombine1DFolder+":S_exp")
1145//     
1146//
1147////   
1148//      Duplicate/O $(ksCombine1DFolder+":Q_exp") $(ksCombine1DFolder+":Q_exp_orig")
1149//      Duplicate/O $(ksCombine1DFolder+":I_exp") $(ksCombine1DFolder+":I_exp_orig")
1150//      Duplicate/O $(ksCombine1DFolder+":S_exp") $(ksCombine1DFolder+":S_exp_orig")
1151//      wave I_exp_orig = $(ksCombine1DFolder+":I_exp_orig")
1152//     
1153//      nq = numpnts($(ksCombine1DFolder+":Q_exp"))
1154////   
1155//
1156////    // append the (blank) wave note to the intensity wave
1157////    Note I_exp,"BOX=0;SPLINE=0;"
1158////    Note I_exp_orig,"BOX=0;SPLINE=0;"
1159////   
1160////    //add data to the graph
1161//      Execute "AppendConcatenated()"
1162//     
1163//      SetDataFolder root:
1164//End
1165//
1166//// remove any q-values <= val
1167//Function RemoveBadQPoints(qw,iw,sw,val)
1168//      Wave qw,iw,sw
1169//      Variable val
1170//     
1171//      Variable ii,num,numBad,qval
1172//      num = numpnts(qw)
1173//     
1174//      ii=0
1175//      numBad=0
1176//      do
1177//              qval = qw[ii]
1178//              if(qval <= val)
1179//                      numBad += 1
1180//              else            //keep the points
1181//                      qw[ii-numBad] = qval
1182//                      iw[ii-numBad] = iw[ii]
1183//                      sw[ii-numBad] = sw[ii]
1184//              endif
1185//              ii += 1
1186//      while(ii<num)
1187//      //trim the end of the waves
1188//      DeletePoints num-numBad, numBad, qw,iw,sw
1189//      return(numBad)
1190//end
1191//
1192//// if mw = Nan, keep the point, if a numerical value, delete it
1193//Function RemoveMaskedPoints(mw,qw,iw,sw)
1194//      Wave mw,qw,iw,sw
1195//     
1196//      Variable ii,num,numBad,mask
1197//      num = numpnts(qw)
1198//     
1199//      ii=0
1200//      numBad=0
1201//      do
1202//              mask = mw[ii]
1203//              if(numtype(mask) != 2)          //if not NaN
1204//                      numBad += 1
1205//              else            //keep the points that are NaN
1206//                      qw[ii-numBad] = qw[ii]
1207//                      iw[ii-numBad] = iw[ii]
1208//                      sw[ii-numBad] = sw[ii]
1209//              endif
1210//              ii += 1
1211//      while(ii<num)
1212//      //trim the end of the waves
1213//      DeletePoints num-numBad, numBad, qw,iw,sw
1214//      return(numBad)
1215//end
1216//
1217//// produces the _msk waves that have the new number of data points
1218////
1219//Function C1D_MaskDoneButton(ctrlName) : ButtonControl
1220//      String ctrlName
1221//
1222//
1223//      Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
1224//      if(!aExists)
1225//              return(1)               //possibly reverted data, no cursor, no Mask wave
1226//      endif
1227//     
1228//      Duplicate/O $(ksCombine1DFolder+":Q_exp_orig"),$(ksCombine1DFolder+":Q_msk")
1229//      Duplicate/O $(ksCombine1DFolder+":I_exp_orig"),$(ksCombine1DFolder+":I_msk")
1230//      Duplicate/O $(ksCombine1DFolder+":S_exp_orig"),$(ksCombine1DFolder+":S_msk")
1231//      Wave Q_msk=$(ksCombine1DFolder+":Q_msk")
1232//      Wave I_msk=$(ksCombine1DFolder+":I_msk")
1233//      Wave S_msk=$(ksCombine1DFolder+":S_msk")
1234//     
1235//      //finish up - trim the data sets and reassign the working set
1236//      Wave MaskData=$(ksCombine1DFolder+":MaskData")
1237//     
1238//      RemoveMaskedPoints(MaskData,Q_msk,I_msk,S_msk)
1239//
1240//      //reset the number of points
1241//      NVAR gNq = $(ksCombine1DFolder+":gNq")
1242//      gNq = numpnts(Q_msk)
1243//     
1244//      Cursor/K A
1245//      HideInfo
1246//     
1247//      return(0)
1248//End
1249//
1250//
1251//// not quite the same as revert
1252//Function C1D_ClearMaskProc(ctrlName) : ButtonControl
1253//      String ctrlName
1254//     
1255//      SetDataFolder $ksCombine1DFolder
1256//     
1257//      Wave Q_exp_orig
1258//      Duplicate/O Q_exp_orig MaskData
1259//      MaskData = NaN          //use all data
1260//                     
1261//      SetDataFolder root:
1262//
1263//      return(0)
1264//end
1265//
1266//// when the mask tab is selected, A must be on the graph
1267//// Displays MaskData wave on the graph
1268////
1269//Function C1D_MyMaskProc(ctrlName) : ButtonControl
1270//      String ctrlName
1271//     
1272//     
1273//      Wave data=$(ksCombine1DFolder+":I_exp_orig")
1274//     
1275//      SetDataFolder $ksCombine1DFolder
1276//     
1277//      Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
1278//             
1279//      if(aExists)             //mask the selected point
1280//              // toggle NaN (keep) or Data value (= masked)
1281//              Wave MaskData
1282//              MaskData[pcsr(A)] = (numType(MaskData[pcsr(A)])==0) ? NaN : data[pcsr(A)]               //if NaN, doesn't plot
1283//      else
1284//              Wave I_exp_orig,Q_exp_orig
1285//              Cursor /A=1/H=1/L=1/P/W=V_Combine_1D_Graph A I_exp_orig leftx(I_exp_orig)
1286//              ShowInfo
1287//              //if the mask wave does not exist, make one
1288//              if(exists("MaskData") != 1)
1289//                      Duplicate/O Q_exp_orig MaskData
1290//                      MaskData = NaN          //use all data
1291//              endif
1292//              Execute "AppendMask()" 
1293//      endif
1294//
1295//      SetDataFolder root:
1296//
1297//      return(0)
1298//End
1299//
1300//// when the mask button is pressed, A must be on the graph
1301//// Displays MaskData wave on the graph
1302////
1303//Function C1D_MaskLTCursor(ctrlName) : ButtonControl
1304//      String ctrlName
1305//
1306//             
1307//      Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
1308//     
1309//      if(!aExists)
1310//              return(1)
1311//      endif
1312//// need to get rid of old smoothed data if data is re-masked
1313////    Execute "RemoveSmoothed()"
1314////    SetDataFolder $(ksCombine1DFolder)
1315////    Killwaves/Z I_smth,Q_smth,S_smth
1316//
1317//      SetDataFolder $(ksCombine1DFolder)
1318//
1319//      Wave data=I_exp_orig
1320//
1321//      Variable pt,ii
1322//      pt = pcsr(A)
1323//      for(ii=pt;ii>=0;ii-=1)
1324//              // toggle NaN (keep) or Data value (= masked)
1325//              Wave MaskData
1326//              MaskData[ii] = (numType(MaskData[ii])==0) ? NaN : data[ii]              //if NaN, doesn't plot
1327//      endfor
1328//
1329//      SetDataFolder root:
1330//      return(0)
1331//End
1332//
1333//// when the mask button is pressed, A must be on the graph
1334//// Displays MaskData wave on the graph
1335////
1336//Function C1D_MaskGTCursor(ctrlName) : ButtonControl
1337//      String ctrlName
1338//     
1339//      Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
1340//     
1341//      if(!aExists)
1342//              return(1)
1343//      endif
1344//// need to get rid of old smoothed data if data is re-masked
1345////    Execute "RemoveSmoothed()"
1346////    SetDataFolder $(ksCombine1DFolder)
1347////    Killwaves/Z I_smth,Q_smth,S_smth
1348//
1349//      SetDataFolder $(ksCombine1DFolder)
1350//
1351//      Wave data=I_exp_orig
1352//     
1353//      Wave MaskData
1354//
1355//      Variable pt,ii,endPt
1356//      endPt=numpnts(MaskData)
1357//      pt = pcsr(A)
1358//      for(ii=pt;ii<endPt;ii+=1)
1359//              // toggle NaN (keep) or Data value (= masked)
1360//              Wave MaskData
1361//              MaskData[ii] = (numType(MaskData[ii])==0) ? NaN : data[ii]              //if NaN, doesn't plot
1362//      endfor
1363//
1364//      SetDataFolder root:
1365//
1366//      return(0)
1367//End
1368//
1369//// when the mask button is pressed, A must be on the graph
1370//// Displays MaskData wave on the graph
1371////
1372//Function C1D_MaskPercent(ctrlName) : ButtonControl
1373//      String ctrlName
1374//     
1375//      Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
1376//     
1377//      if(!aExists)
1378//              return(1)
1379//      endif
1380//
1381//
1382//      SetDataFolder $(ksCombine1DFolder)
1383//
1384//      Wave data=I_exp_orig
1385//      Wave s_orig = S_exp_orig
1386//      Wave MaskData
1387//
1388//
1389//      Variable pct,ii,endPt
1390//      endPt=numpnts(MaskData)
1391//
1392//      pct = 0.05
1393//     
1394//      for(ii=0;ii<endPt;ii+=1)
1395//              // toggle NaN (keep) or Data value (= masked)
1396//
1397//              MaskData[ii] = (abs(s_orig[ii]/data[ii]) < pct) ? NaN : data[ii]                //if NaN, doesn't plot
1398//      endfor
1399//
1400//
1401//      SetDataFolder root:
1402//
1403//      return(0)
1404//End
1405//
1406//
1407//
1408//
1409//Function CleanUpJunk()
1410//
1411//      // clean up the old junk on the graph, /Z for no error
1412//      // TODO:
1413//      // -- activate both of these functions to clean old data off of the graph
1414////    Execute "RemoveOldData()"
1415//      Execute "RemoveMask()"
1416//     
1417//      //remove the cursor
1418//      Cursor/K A
1419//     
1420//      //always re-initialize these
1421//      String/G $(ksCombine1DFolder+":gStr1") = ""
1422//
1423//      // clean up the old waves from smoothing and desmearing steps
1424//      SetDataFolder $(ksCombine1DFolder)
1425//      Killwaves/Z MaskData,Q_msk,I_msk,S_msk
1426//      SetDataFolder root:
1427//End
1428//
1429//
1430//
1431//// I_dsm is the desmeared data
1432////
1433//// step (7) - desmearing is done, write out the result
1434////
1435//Function C1D_SaveButtonProc(ctrlName) : ButtonControl
1436//      String ctrlName
1437//
1438//
1439//      String saveStr
1440//      SVAR curFile = $(ksCombine1DFolder+":gCurFile")
1441//      saveStr = CleanupName((curFile),0)              //the output filename
1442//      //
1443//
1444//      V_Write_VSANSMasked1D(saveStr,0,0,1)                    //use the full set (lo=hi=0) and present a dialog
1445//     
1446//      SetDataFolder root:
1447//      return(0)
1448//End
1449//
1450//Function C1D_HelpButtonProc(ctrlName) : ButtonControl
1451//      String ctrlName
1452//
1453//      DisplayHelpTopic/Z/K=1 "Combining VSANS Data"
1454//      if(V_flag !=0)
1455//              DoAlert 0,"The Combining VSANS Data Help file could not be found"
1456//      endif
1457//      return(0)
1458//End
1459//
1460//
1461////toggles the log/lin display of the loaded data set
1462//Function C1D_LoadCheckProc(ctrlName,checked) : CheckBoxControl
1463//      String ctrlName
1464//      Variable checked
1465//
1466//      ModifyGraph log=(checked)
1467//      return(0)
1468//End
1469//
1470//
1471//
1472//
1473//
1474//// TODO:
1475//// -- either update this to be correct for VSANS, or dispatch to some other data writer.
1476////
1477//Function V_Write_VSANSMasked1D(fullpath,lo,hi,dialog)
1478//      String fullpath
1479//      Variable lo,hi,dialog           //=1 will present dialog for name
1480//     
1481//     
1482//      String termStr="\r\n"
1483//      String destStr = ksCombine1DFolder
1484//      String formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr
1485//     
1486//      Variable refNum,integer,realval
1487//     
1488//      //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error****
1489//      WAVE Q_msk=$(destStr + ":Q_msk")
1490//      WAVE I_msk=$(destStr + ":I_msk")
1491//      WAVE S_msk=$(destStr + ":S_msk")
1492//     
1493//      //check each wave
1494//      If(!(WaveExists(Q_msk)))
1495//              Abort "Q_msk DNExist in WriteUSANSDesmeared()"
1496//      Endif
1497//      If(!(WaveExists(I_msk)))
1498//              Abort "I_msk DNExist in WriteUSANSDesmeared()"
1499//      Endif
1500//      If(!(WaveExists(S_msk)))
1501//              Abort "S_msk DNExist in WriteUSANSDesmeared()"
1502//      Endif
1503//     
1504//      // TODO:
1505//      // -- this remnant from desmearing creates fake resolution waves!!!
1506//      // -- correctly handle the input resolution waves
1507//      // make dummy waves to hold the "fake" resolution, and write it as the last 3 columns
1508//      //
1509//      Duplicate/O Q_msk,res1,res2,res3
1510//      res3 = 1                // "fake" beamstop shadowing
1511//      res1 /= 100             //make the sigmaQ so small that there is no smearing
1512//     
1513//      if(dialog)
1514//              Open/D refnum as fullpath+".cmb"                //won't actually open the file
1515//              If(cmpstr(S_filename,"")==0)
1516//                      //user cancel, don't write out a file
1517//                      Close/A
1518//                      Abort "no data file was written"
1519//              Endif
1520//              fullpath = S_filename
1521//      Endif
1522//     
1523//      //write out partial set?
1524//      Duplicate/O Q_msk,tq,ti,te
1525//      ti=I_msk
1526//      te=S_msk
1527//      if( (lo!=hi) && (lo<hi))
1528//              redimension/N=(hi-lo+1) tq,ti,te,res1,res2,res3         //lo to hi, inclusive
1529//              tq=Q_msk[p+lo]
1530//              ti=I_msk[p+lo]
1531//              te=S_msk[p+lo]
1532//      endif
1533//     
1534//      //tailor the output given the type of data written out...
1535//      String samStr="",dateStr="",str1,str2
1536//
1537//     
1538//      samStr = fullpath
1539//      dateStr="CREATED: "+date()+" at  "+time()
1540//
1541//
1542//     
1543//      //actually open the file
1544//      Open refNum as fullpath
1545//     
1546//      fprintf refnum,"%s"+termStr,samStr
1547////    fprintf refnum,"%s"+termStr,str1
1548////    fprintf refnum,"%s"+termStr,str2
1549//      fprintf refnum,"%s"+termStr,dateStr
1550//     
1551//      wfprintf refnum, formatStr, tq,ti,te,res1,res2,res3
1552//     
1553//      Close refnum
1554//     
1555//      Killwaves/Z ti,tq,te,res1,res2,res3
1556//     
1557//      Return(0)
1558//End
1559//
1560//
1561//
1562//
1563//Function V_GetScalingInOverlap(num2,wave1q,wave1i,wave2q,wave2i)
1564//      Variable num2           //largest point number of wave2 in overlap region
1565//      Wave wave1q,wave1i,wave2q,wave2i                //1 = first dataset, 2= second dataset
1566//
1567//      Variable ii,ival1,newi,ratio
1568//      ratio=0
1569//      ii=0
1570//      do
1571//              //get scaling factor at each point of wave 2 in the overlap region
1572//              newi = interp(wave2q[ii],wave1q,wave1i)         //get the intensity of wave1 at an overlap point
1573//              ratio += newi/wave2i[ii]                                        //get the scale factor
1574//              //Print "ratio = ",ratio
1575//              ii+=1
1576//      while(ii<=num2)
1577//      Variable val
1578//      val = ratio/(num2+1)            // +1 counts for point zero
1579//      //Print "val = ",val
1580//
1581//      Variable tol=1.05                       //5% is the preferred number (for Andrew and Lionel, at least)
1582//
1583////    ControlInfo/W=NSORT_Panel WarningCheck
1584////    if(( V_Value==1 ) && ( (val > tol) || (val < 1/tol) ) )
1585////            String str=""
1586////            sprintf str,"The scaling factor is more than a factor of %g from 1. Proceed with caution.\r",tol
1587////            DoAlert 0,str
1588////    endif
1589//     
1590//      Return val
1591//End
1592
Note: See TracBrowser for help on using the repository browser.