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

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

cleaning up a lot of the TODO items from the code.

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