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

Last change on this file since 1038 was 1038, checked in by srkline, 6 years ago

Adding procedures to allow trimming of data sets before concatenation. This is different than SANS, since the trimming and scaling choices must be made before reduction is done, since they must be part of the reduction protocol - as all data sets I(q) are part of the same data file.

How this is handled is still very much a work in progress...

File size: 31.8 KB
Line 
1#pragma TextEncoding = "MacRoman"
2#pragma rtGlobals=3             // Use modern global access method and strict wave access.
3
4
5//
6//
7// Preliminary routines for adjusting, masking, and combining 1D VSANS data sets.
8//
9// ideas taken from USANS to mask data sets
10// avoiding duplication of NSORT, since autoscale is not in favor, and there may be anywhere
11//   from 3 to 9 data sets to combine
12//
13// masking waves are saved in the "Combine_1D" folder, BUT the masking may eventually be part
14//  of the data reduction protocol - and anything in work folders will be lost
15//
16
17
18//ksWorkFolderList
19
20//      String str,winStr="V_1D_Data"
21//      sprintf str,"(\"%s\",%d,\"%s\")",type,popNum,winStr
22//
23//      Execute ("V_Back_IQ_Graph"+str)
24//      Execute ("V_Middle_IQ_Graph"+str)
25//      Execute ("V_Front_IQ_Graph"+str)
26
27
28// draws the graph, but does not draw anything on it yet
29//
30// TODO:
31// -- make  the data folder list for the popup
32// -- make the data folder popup do the work of plotting (test for failure)
33//
34// -- make a button to show the default table, and set up dependencies to link to the graph display
35// -- have an "active" data set to trim, or make duplicates for all of the data sets
36//
37// -- button to convert the points to strings that can be used and written to data files?
38//
39// -- table is continually duplicated
40// -- AutoPosition the windows next to each other
41// -- (different)(not ugly) color for the control bar so it's distinguishable from the regular data plot
42// -- "Done" button that kills the root:ToTrim folder (may need to kill the dependency first)
43//
44Proc V_CombineDataGraph()
45
46        DoWindow/F V_1D_Combine
47        if(V_flag==0)
48                Variable num,ii
49                String detStr
50               
51                Display /W=(277,526,748,938)/N=V_1D_Combine/K=1
52
53                ControlBar 70
54                ModifyGraph cbRGB=(44000,44000,44000)
55               
56                PopupMenu popup1,pos={15,5},size={90,20},title="Data Folder"
57                PopupMenu popup1,help={"data folder"}
58                PopupMenu popup1,value= GetAList(4),proc=V_DataFolderPlotPop
59               
60                PopupMenu popup0,pos={200,5},size={70,20},title="Bin Type"
61                PopupMenu popup0,help={"binning type"}
62                PopupMenu popup0,value= ksBinTypeStr
63//              PopupMenu popup0,mode=1,proc=V_BinningModePopup
64
65                CheckBox check0,pos={18.00,36.00},size={57.00,16.00},proc=V_Plot1D_LogCheckProc,title="Log Axes"
66                CheckBox check0,value= 1
67
68                Button AllQ,pos={320,28},size={70,20},proc=V_AllQ_Plot_1D_ButtonProc,title="All Q"
69                Button AllQ,help={"Show the full q-range of the dataset"}
70               
71                Legend/C/N=text0/J/X=72.00/Y=60.00
72
73                //trust that the table is present? No, but don't overwrite the data in the waves
74                // unless any one of the three doesn't exist
75                if(exists("PanelNameW") == 0 || exists("Beg_pts") == 0 || exists("End_pts") == 0)
76                        Make/O/T/N=(ItemsInList(ksPanelBinTypeList)) PanelNameW
77                        Make/O/D/N=(ItemsInList(ksPanelBinTypeList)) Beg_pts
78                        Make/O/D/N=(ItemsInList(ksPanelBinTypeList)) End_pts
79               
80                        num = ItemsInList(ksPanelBinTypeList)
81                        ii=0
82                        do
83                                detStr = StringFromList(ii, ksPanelBinTypeList)
84                                Beg_pts[ii]  = NumberByKey(detStr, ksBinTrimBegDefault,"=",";")
85                                End_pts[ii] = NumberByKey(detStr, ksBinTrimEndDefault,"=",";")
86                                PanelNameW[ii] = detStr
87                                ii += 1
88                        while(ii<num)
89                       
90                endif
91               
92                Edit/K=0 root:PanelNameW,root:Beg_pts,root:End_pts             
93
94                Make/O/D/N=1 trimUpdate
95                trimUpdate := V_DummyUpdate(Beg_pts, End_pts)
96               
97//              PopupMenu ymodel,pos={150,5},size={71,20},title="y-axis"
98//              PopupMenu ymodel,help={"This popup selects how the y-axis will be linearized based on the chosen data"}
99//              PopupMenu ymodel,value= #"\"I;log(I);ln(I);1/I;I^a;Iq^a;I^a q^b;1/sqrt(I);ln(Iq);ln(Iq^2)\""
100//              PopupMenu ymodel,mode=NumVarOrDefault("root:Packages:NIST:VSANS:Globals:Plot_1d:gYMode", 1 ),proc=V_YMode_PopMenuProc
101//              PopupMenu xmodel,pos={220,5},size={74,20},title="x-axis"
102//              PopupMenu xmodel,help={"This popup selects how the x-axis will be linearized given the chosen data"}
103//              PopupMenu xmodel,value= #"\"q;log(q);q^2;q^c\""
104//              PopupMenu xmodel,mode=NumVarOrDefault("root:Packages:NIST:VSANS:Globals:Plot_1d:gXMode", 1 ),proc=V_XMode_PopMenuProc
105////            Button Rescale,pos={281,5},size={70,20},proc=V_Rescale_Plot_1D_ButtonProc,title="Rescale"
106////            Button Rescale,help={"Rescale the x and y-axes of the data"},disable=1
107//
108//              SetVariable expa,pos={120,28},size={80,15},title="pow \"a\""
109//              SetVariable expa,help={"This sets the exponent \"a\" for some y-axis formats. The value is ignored if the model does not use an adjustable exponent"}
110//              SetVariable expa,limits={-2,10,0},value= root:Packages:NIST:VSANS:Globals:Plot_1d:gExpA
111//              SetVariable expb,pos={120,46},size={80,15},title="pow \"b\""
112//              SetVariable expb,help={"This sets the exponent \"b\" for some x-axis formats. The value is ignored if the model does not use an adjustable exponent"}
113//              SetVariable expb,limits={0,10,0},value= root:Packages:NIST:VSANS:Globals:Plot_1d:gExpB
114//
115//              SetVariable expc,pos={220,28},size={80,15},title="pow \"c\""
116//              SetVariable expc,help={"This sets the exponent \"c\" for some x-axis formats. The value is ignored if the model does not use \"c\" as an adjustable exponent"}
117//              SetVariable expc,limits={-10,10,0},value= root:Packages:NIST:VSANS:Globals:Plot_1d:gExpC
118
119        endif
120               
121       
122End
123
124Function V_DummyUpdate(Beg_pts, End_pts)
125        Wave Beg_pts,End_pts
126       
127        // trim the data displayed
128        // do this by setting the iBin values to NaN, so it won't display
129        // won't hurt to set twice...
130       
131        Wave/T panelStr = root:PanelNameW
132        Wave begW = root:Beg_pts
133        Wave endW = root:End_pts
134       
135        SetDataFolder root:ToTrim
136       
137        Variable num,ii
138        String str,detStr
139        num=numpnts(panelStr)
140       
141        for(ii=0;ii<num;ii+=1)
142                detStr = panelStr[ii]
143                Wave/Z iw = $("iBin_qxqy_"+detStr+"_trim")
144//              Wave/Z iw = $("iBin_qxqy_"+detStr)
145//              Wave/Z ew = $("eBin_qxqy_"+detStr)
146                if(WaveExists(iw))
147                       
148//                      DeletePoints 0,nBeg, qw,iw,ew
149                        iw[0,begW[ii]-1] = NaN
150                               
151                        Variable npt
152                        npt = numpnts(iw)
153//                      DeletePoints npt-nEnd,nEnd, qw,iw,ew
154                        iw[npt-endW[ii],npt-1] = NaN
155                       
156                endif
157               
158        endfor
159       
160        SetDataFolder root:
161
162        return(0)
163End
164
165
166Function V_DataFolderPlotPop(ctrlName,popNum,popStr) : PopupMenuControl
167        String ctrlName
168        Variable popNum // which item is currently selected (1-based)
169        String popStr           // contents of current popup item as string
170
171
172        String str,winStr="V_1D_Combine",dataType
173        Variable binType,num,ii
174        ControlInfo popup0
175        binType = V_BinTypeStr2Num(S_Value)
176       
177        //dataType now needs to be the full path to the folder
178        dataType = "root:"+popStr
179       
180        sprintf str,"(\"%s\",%d,\"%s\")",dataType,binType,winStr
181
182        Execute ("V_Back_IQ_Graph"+str)
183        Execute ("V_Middle_IQ_Graph"+str)
184        Execute ("V_Front_IQ_Graph"+str)
185
186        ModifyGraph marker=8,opaque=1,msize=3           //make the traces open white circles
187
188
189        NewDataFolder/O root:ToTrim
190       
191        //remove all of the "toTrim" data from the graph, if it's there
192        String type
193       
194        SetDataFolder root:ToTrim
195       
196        for(ii=0;ii<ItemsInList(ksPanelBinTypeList);ii+=1)
197                type = StringFromList(ii, ksPanelBinTypeList, ";")
198                CheckDisplayed/W=$winStr $("iBin_qxqy_"+type+"_trim")
199                if(V_flag==1)
200                        RemoveFromGraph/W=$winStr $("iBin_qxqy_"+type+"_trim")
201                endif
202        endfor
203       
204        SetDataFolder root:
205       
206//      ClearIQIfDisplayed_AllFldr("B_trim",winStr)
207//      ClearIQIfDisplayed_AllFldr("ML_trim",winStr)
208//      ClearIQIfDisplayed_AllFldr("MR_trim",winStr)
209//      ClearIQIfDisplayed_AllFldr("MT_trim",winStr)
210//      ClearIQIfDisplayed_AllFldr("MB_trim",winStr)
211//      ClearIQIfDisplayed_AllFldr("FL_trim",winStr)
212//      ClearIQIfDisplayed_AllFldr("FR_trim",winStr)
213//      ClearIQIfDisplayed_AllFldr("FT_trim",winStr)
214//      ClearIQIfDisplayed_AllFldr("FB_trim",winStr)
215//      ClearIQIfDisplayed_AllFldr("MLR_trim",winStr)
216//      ClearIQIfDisplayed_AllFldr("MTB_trim",winStr)
217//      ClearIQIfDisplayed_AllFldr("FLR_trim",winStr)
218//      ClearIQIfDisplayed_AllFldr("FTB_trim",winStr)
219//      ClearIQIfDisplayed_AllFldr("MLRTB_trim",winStr)
220//      ClearIQIfDisplayed_AllFldr("FLRTB_trim",winStr)
221
222        //then kill the data folder, so it can be duplicated
223       
224//
225//      // rename all of the data in the new folder
226        SetDataFolder $dataType
227        String list = WaveList("*",";","")              //must be in the correct data folder
228        SetDataFolder root:
229//      Print list     
230        num = ItemsInList(list)
231        for(ii=0;ii<num;ii+=1)
232                str = StringFromList(ii,list)
233                Duplicate/O $(dataType+":"+str), $("root:ToTrim:"+str+"_trim")
234        endfor
235        // plot the linked data
236        sprintf str,"(\"%s\",%d,\"%s\")","root:ToTrim",binType,winStr
237
238        Execute ("V_Back_IQ_Graph_trim"+str)
239        Execute ("V_Middle_IQ_Graph_trim"+str)
240        Execute ("V_Front_IQ_Graph_trim"+str)
241        // and link the data to the table with a dependency
242//     
243       
244       
245        return(0)       
246End
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279//////////////// Below is unused -- it was started, but seems like the wrong approach,
280//////////////// so I have abandoned it for now
281
282
283
284////////////////
285// TODO:
286// x- add a popup to the load tab to set the work folder
287// x- add this file to the Includes list and to the SVN folder
288// -- add button (mask tab) to save mask
289// -- add button (mask tab) to recall mask
290// -- think of ways to run through the files batchwise (instead of adding this to the protocol)
291// -- link the main entry procedure to the main panel
292//
293// -- when do I concatenate the data sets?
294// ---- do I add a concatenate button to the Load tab, then this single set is the
295//    starting point for the MASK tab
296// ---- the Load Data button could then be a loader for a single file, which is then the "concatenated"
297//     starting point...
298//
299// x- make the graph larger for easier viewing of the data
300// -- increase the size of the tab control, rearrange the other controls
301//
302// -- how do I incorporate the rescaling?
303//
304// -- error bars on the graph
305// x- legend on the graph
306//
307// x- define a new folder for all of this -- NOT the protocol folder
308// x- define a string constant with this path
309//
310// -- button to mask based on relative error threshold for each data point. may be a good startng point for
311//    masking
312//
313// -- remove the mask by relative error button - this is not really a good idea.
314//
315//
316
317
318StrConstant ksCombine1DFolder = "root:Packages:NIST:VSANS:Globals:Combine_1D"
319
320// main entry routine
321Macro V_Combine_1D()
322
323        //check for the correct folder, initialize if necessary
324        //
325        if(DataFolderExists(ksCombine1DFolder) == 0)
326                Execute "V_Init_Combine_1D()"
327        endif
328       
329        SetDataFolder root:
330       
331        DoWindow/F V_Combine_1D_Graph
332        if(V_flag==0)
333                Execute "V_Combine_1D_Graph()"
334        endif
335End
336
337Proc V_Init_Combine_1D()
338
339        //set up the folder(s) needed
340        NewDataFolder/O $(ksCombine1DFolder)
341       
342        SetDataFolder $(ksCombine1DFolder)
343       
344        String/G gCurFile=""
345        String/G gStr1=""
346        Variable/G gFreshMask=1
347        Variable/G gNq=0
348       
349        SetDataFolder root:
350End
351
352
353////
354//
355//
356Proc V_Combine_1D_Graph()
357
358        PauseUpdate; Silent 1           // building window...
359        Display /W=(699,45,1328,779) /K=1
360        ModifyGraph cbRGB=(51664,44236,58982)
361        ModifyGraph tickUnit=1
362        DoWindow/C V_Combine_1D_Graph
363        ControlBar 160
364        // break into tabs
365        TabControl C1D_Tab,pos={5,3},size={392,128},proc=C1D_TabProc
366        TabControl C1D_Tab,labelBack=(49151,49152,65535),tabLabel(0)="Load"
367        TabControl C1D_Tab,tabLabel(1)="Mask",tabLabel(2)="Rescale",value=0
368       
369        //always visible - revert and save
370        //maybe the wrong place here?
371        Button C1DControlA,pos={225,135},size={80,20},proc=C1D_RevertButtonProc,title="Revert"
372        Button C1DControlA,help={"Revert the data to its original state and start over"}
373        Button C1DControlB,pos={325,135},size={50,20},proc=C1D_SaveButtonProc,title="Save"
374        Button C1DControlB,help={"Save the masked and scaled data set"}
375        Button C1DControlC,pos={25,135},size={50,20},proc=C1D_HelpButtonProc,title="Help"
376        Button C1DControlC,help={"Show the help file for combining VSANS data sets"}
377       
378        // add the controls to each tab ---- all names start with "C1DControl_"
379
380        //tab(0) Load - initially visible
381        Button C1DControl_0a,pos={23,39},size={80,20},proc=C1D_LoadButtonProc,title="Load Data"
382        Button C1DControl_0a,help={"Load slit-smeared USANS data = \".cor\" files"}
383        CheckBox C1DControl_0b,pos={26,74},size={80,14},proc=C1D_LoadCheckProc,title="Log Axes?"
384        CheckBox C1DControl_0b,help={"Toggle Log/Lin Q display"},value= 1
385        TitleBox C1DControl_0c,pos={120,37},size={104,19},font="Courier",fSize=10
386        TitleBox C1DControl_0c,variable= $(ksCombine1DFolder+":gStr1")
387        PopupMenu C1DControl_0d,pos={120,75},size={71,20},title="Bin Type"
388        PopupMenu C1DControl_0d,help={"This popup selects how the y-axis will be linearized based on the chosen data"}
389        PopupMenu C1DControl_0d,value= ksBinTypeStr
390        PopupMenu C1DControl_0d,mode=1,proc=V_CombineModePopup
391        PopupMenu C1DControl_0e,pos={120,100},size={109,20},title="Data Source"
392        PopupMenu C1DControl_0e,mode=1,popvalue="RAW",value= #"\"RAW;SAM;EMP;BGD;COR;ABS;\""           
393        Button C1DControl_0f,pos={200,39},size={120,20},proc=C1D_ConcatButtonProc,title="Concatenate"
394        Button C1DControl_0f,help={"Load slit-smeared USANS data = \".cor\" files"}
395
396       
397        //tab(1) Mask
398        Button C1DControl_1a,pos={20,35},size={90,20},proc=C1D_MyMaskProc,title="Mask Point"            //bMask
399        Button C1DControl_1a,help={"Toggles the masking of the selected data point"}
400        Button C1DControl_1a,disable=1
401        Button C1DControl_1b,pos={20,65},size={140,20},proc=C1D_MaskGTCursor,title="Mask Q >= Cursor"           //bMask
402        Button C1DControl_1b,help={"Toggles the masking of all q-values GREATER than the current cursor location"}
403        Button C1DControl_1b,disable=1
404        Button C1DControl_1c,pos={20,95},size={140,20},proc=C1D_MaskLTCursor,title="Mask Q <= Cursor"           //bMask
405        Button C1DControl_1c,help={"Toggles the masking of all q-values LESS than the current cursor location"}
406        Button C1DControl_1c,disable=1
407        Button C1DControl_1d,pos={180,35},size={90,20},proc=C1D_ClearMaskProc,title="Clear Mask"                //bMask
408        Button C1DControl_1d,help={"Clears all mask points"}
409        Button C1DControl_1d,disable=1
410        Button C1DControl_1e,pos={180,65},size={90,20},proc=C1D_MaskPercent,title="Percent Mask"                //bMask
411        Button C1DControl_1e,help={"Clears all mask points"}
412        Button C1DControl_1e,disable=1
413       
414       
415//      Button C1DControl_1b,pos={144,66},size={110,20},proc=C1D_MaskDoneButton,title="Done Masking"
416//      Button C1DControl_1b,disable=1
417       
418//      //tab(2) Rescale
419        Button C1DControl_2a,pos={31,42},size={90,20},proc=C1D_ExtrapolateButtonProc,title="Extrapolate"
420        Button C1DControl_2a,help={"Extrapolate the high-q region with a power-law"}
421        Button C1DControl_2a,disable=1
422        SetVariable C1DControl_2b,pos={31,70},size={100,15},title="# of points"
423        SetVariable C1DControl_2b,help={"Set the number of points for the power-law extrapolation"}
424        SetVariable C1DControl_2b,limits={5,100,1},value=_NUM:123
425        SetVariable C1DControl_2b,disable=1
426        CheckBox C1DControl_2c,pos={157,45},size={105,14},proc=C1D_ExtrapolationCheckProc,title="Show Extrapolation"
427        CheckBox C1DControl_2c,help={"Show or hide the high q extrapolation"},value= 1
428        CheckBox C1DControl_2c,disable=1
429        SetVariable C1DControl_2d,pos={31,96},size={150,15},title="Power Law Exponent"
430        SetVariable C1DControl_2d,help={"Power Law exponent from the fit = the DESMEARED slope - override as needed"}
431        SetVariable C1DControl_2d format="%5.2f"
432        SetVariable C1DControl_2d,limits={-inf,inf,0},value=_NUM:123
433        SetVariable C1DControl_2d,disable=1
434       
435        Legend/C/N=text0/J/X=72.00/Y=60.00
436
437       
438        SetDataFolder root:
439EndMacro
440
441//
442// recalculate the I(q) binning. no need to adjust model function or views
443// just rebin
444//
445// see V_BinningModePopup() in V_DataPlotting.ipf for a duplicate verison of this function
446Function V_CombineModePopup(ctrlName,popNum,popStr) : PopupMenuControl
447        String ctrlName
448        Variable popNum // which item is currently selected (1-based)
449        String popStr           // contents of current popup item as string
450
451// TODO
452// x- replace the type with selection from the panel - don't use the current display type
453        ControlInfo C1DControl_0e
454        String type = S_Value
455
456        SVAR gStr1 = $(ksCombine1DFolder+":gStr1")
457        gStr1 = type
458       
459       
460        V_QBinAllPanels(type,popNum)
461
462
463        String str,winStr="V_Combine_1D_Graph"
464        sprintf str,"(\"%s\",%d,\"%s\")",type,popNum,winStr
465
466// TODO:
467// x- replace these calls -- they work with the 1d plot, not this panel. I want them to do basically the same
468//    exact things, but with a different target window
469//  *** these calls now take the target window as a parameter - so that there is only one version
470        Execute ("V_Back_IQ_Graph"+str)
471        Execute ("V_Middle_IQ_Graph"+str)
472        Execute ("V_Front_IQ_Graph"+str)
473               
474       
475        return(0)       
476End
477
478
479// function to control the drawing of buttons in the TabControl on the main panel
480// Naming scheme for the buttons MUST be strictly adhered to... else buttons will
481// appear in odd places...
482// all buttons are named C1DControl_NA where N is the tab number and A is the letter denoting
483// the button's position on that particular tab.
484// in this way, buttons will always be drawn correctly :-)
485//
486Function C1D_TabProc(ctrlName,tab) //: TabControl
487        String ctrlName
488        Variable tab
489
490        String ctrlList = ControlNameList("",";"),item="",nameStr=""
491        Variable num = ItemsinList(ctrlList,";"),ii,onTab
492        for(ii=0;ii<num;ii+=1)
493                //items all start w/"C1DControl_"               //11 characters
494                item=StringFromList(ii, ctrlList ,";")
495                nameStr=item[0,10]
496                if(cmpstr(nameStr,"C1DControl_")==0)
497                        onTab = str2num(item[11])                       //12th is a number
498                        ControlInfo $item
499                        switch(abs(V_flag))     
500                                case 1:
501                                        Button $item,disable=(tab!=onTab)
502                                        break
503                                case 2:
504                                        CheckBox $item,disable=(tab!=onTab)
505                                        break
506                                case 5:
507                                        SetVariable $item,disable=(tab!=onTab)
508                                        break
509                                case 10:       
510                                        TitleBox $item,disable=(tab!=onTab)
511                                        break
512                                case 4:
513                                        ValDisplay $item,disable=(tab!=onTab)
514                                        break
515                                case 3:
516                                        PopupMenu $item,disable=(tab!=onTab)
517                                        break
518                                // add more items to the switch if different control types are used
519                        endswitch
520                       
521                endif
522        endfor
523       
524        // remove the mask if I go back to the data?
525        if(tab==0)
526                RemoveMask()
527//              RemoveConcatenated()
528        endif
529       
530        // masking
531        if(tab==1)
532                C1D_ClearMaskProc("")           //starts with a blank mask
533                C1D_MyMaskProc("")              //start masking if you click on the tab
534        else
535                C1D_MaskDoneButton("")          //masking is done if you click off the tab
536        endif
537       
538        // rescaling
539        if(tab == 2)
540        // TODO
541        // -- fill this in
542        // -- this is still in the thought process at this point
543       
544// do rescaling of the different sections of the data set
545               
546        endif
547       
548        return 0
549End
550
551
552Proc AppendConcatenated()
553
554        if( strsearch(TraceNameList("V_Combine_1D_Graph", "", 1),"I_exp_orig",0,2) == -1)                       //Igor 5
555                SetDataFolder $(ksCombine1DFolder)
556                AppendToGraph/W=V_Combine_1D_Graph I_exp_orig vs Q_exp_orig
557                ModifyGraph mode(I_exp_orig)=3,marker(I_exp_orig)=19,msize(I_exp_orig)=2,opaque(I_exp_orig)=1
558                ModifyGraph rgb(I_exp_orig)=(0,0,0)
559               
560                ModifyGraph tickUnit=1,log=1
561                Modifygraph grid=1,mirror=2
562
563                ErrorBars/T=0 I_exp_orig Y,wave=(S_exp_orig,S_exp_orig)
564               
565                setdatafolder root:
566        endif
567end
568
569Function RemoveConcatenated()
570
571        SetDataFolder $(ksCombine1DFolder)
572        RemoveFromGraph/W=V_Combine_1D_Graph/Z I_exp_orig
573        setdatafolder root:
574end
575
576Proc AppendMask()
577
578        if( strsearch(TraceNameList("V_Combine_1D_Graph", "", 1),"MaskData",0,2) == -1)                 //Igor 5
579                SetDataFolder $(ksCombine1DFolder)
580                AppendToGraph/W=V_Combine_1D_Graph MaskData vs Q_exp_orig
581                ModifyGraph mode(MaskData)=3,marker(MaskData)=8,msize(MaskData)=2.5,opaque(MaskData)=1
582                ModifyGraph rgb(MaskData)=(65535,16385,16385)
583               
584                setdatafolder root:
585        endif
586end
587
588
589
590Function RemoveMask()
591
592        SetDataFolder $(ksCombine1DFolder)
593        RemoveFromGraph/W=V_Combine_1D_Graph/Z MaskData
594        setdatafolder root:
595end
596
597
598// concatenate the data, and replace the multiple data sets with the concatenated set
599// - then you can proceed to the mask tab
600//
601Function C1D_ConcatButtonProc(ctrlName) : ButtonControl
602        String ctrlName
603
604
605        ControlInfo C1DControl_0e
606        String folderStr = S_Value
607
608        SVAR gStr1 = $(ksCombine1DFolder+":gStr1")
609        gStr1 = folderStr
610
611
612        ControlInfo C1DControl_0d
613        Variable binType = V_BinTypeStr2Num(S_Value)
614       
615        V_1DConcatenate(folderStr,binType)
616
617// sort the data set
618        V_TmpSort1D(folderStr)
619       
620// now copy the concatenated data over to the combine folder   
621        Duplicate/O $("root:Packages:NIST:VSANS:"+folderStr+":tmp_q") $(ksCombine1DFolder+":Q_exp")             
622        Duplicate/O $("root:Packages:NIST:VSANS:"+folderStr+":tmp_i") $(ksCombine1DFolder+":I_exp")             
623        Duplicate/O $("root:Packages:NIST:VSANS:"+folderStr+":tmp_s") $(ksCombine1DFolder+":S_exp")     
624        wave Q_exp = $(ksCombine1DFolder+":Q_exp")
625        Wave I_exp = $(ksCombine1DFolder+":I_exp")
626        Wave S_exp = $(ksCombine1DFolder+":S_exp")
627       
628
629//     
630        Duplicate/O $(ksCombine1DFolder+":Q_exp") $(ksCombine1DFolder+":Q_exp_orig")
631        Duplicate/O $(ksCombine1DFolder+":I_exp") $(ksCombine1DFolder+":I_exp_orig")
632        Duplicate/O $(ksCombine1DFolder+":S_exp") $(ksCombine1DFolder+":S_exp_orig")
633        wave I_exp_orig = $(ksCombine1DFolder+":I_exp_orig")
634       
635        Variable nq = numpnts($(ksCombine1DFolder+":Q_exp"))
636//     
637
638//      // append the (blank) wave note to the intensity wave
639//      Note I_exp,"BOX=0;SPLINE=0;"
640//      Note I_exp_orig,"BOX=0;SPLINE=0;"
641//     
642//      //add data to the graph
643        Execute "AppendConcatenated()" 
644       
645        // TODO:
646        // -- do I clear off the old data here, or somewhere else?
647        // clear off the old data from the individual panels
648        // use ClearAllIQIfDisplayed()
649        ClearIQIfDisplayed_AllBin(folderStr,"V_Combine_1D_Graph")
650
651        RemoveMask()
652       
653        return(0)
654End
655
656// step (1) - get the data from a WORK folder, and plot it
657// clear out all of the "old" waves, remove them from the graph first
658//
659// ??produces Q_exp, I_exp, S_exp waves (and originals "_orig")
660// add a dummy wave note that can be changed on later steps
661//
662Function C1D_LoadButtonProc(ctrlName) : ButtonControl
663        String ctrlName
664
665
666        String qStr,iStr,sStr,sqStr
667        Variable nq,dqv,numBad,val
668       
669        // remove any of the old traces on the graph and delete the waves and reset the global strings
670        CleanUpJunk()
671       
672        SetDataFolder root:
673       
674        // go get the new data
675        Execute "A_LoadOneDDataWithName(\"\",0)"
676
677// TODO:       
678        // x-Missing something here from the loader - go back to the LakeDesmearing ipf
679        SVAR fname = root:Packages:NIST:gLastFileName           //this is the 1D file loaded
680
681//     
682        qStr = CleanupName((fName + "_q"),0)            //the q-wave
683        iStr = CleanupName((fName + "_i"),0)            //the i-wave
684        sStr = CleanupName((fName + "_s"),0)            //the s-wave
685//      sqStr = CleanupName((fName + "sq"),0)           //the sq-wave
686//
687        String DFStr= CleanupName(fname,0)
688//     
689        Duplicate/O $("root:"+DFStr+":"+qStr) $(ksCombine1DFolder+":Q_exp")             
690        Duplicate/O $("root:"+DFStr+":"+iStr) $(ksCombine1DFolder+":I_exp")             
691        Duplicate/O $("root:"+DFStr+":"+sStr) $(ksCombine1DFolder+":S_exp")     
692        wave Q_exp = $(ksCombine1DFolder+":Q_exp")
693        Wave I_exp = $(ksCombine1DFolder+":I_exp")
694        Wave S_exp = $(ksCombine1DFolder+":S_exp")
695       
696
697//     
698        Duplicate/O $(ksCombine1DFolder+":Q_exp") $(ksCombine1DFolder+":Q_exp_orig")
699        Duplicate/O $(ksCombine1DFolder+":I_exp") $(ksCombine1DFolder+":I_exp_orig")
700        Duplicate/O $(ksCombine1DFolder+":S_exp") $(ksCombine1DFolder+":S_exp_orig")
701        wave I_exp_orig = $(ksCombine1DFolder+":I_exp_orig")
702       
703        nq = numpnts($(ksCombine1DFolder+":Q_exp"))
704//     
705
706//      // append the (blank) wave note to the intensity wave
707//      Note I_exp,"BOX=0;SPLINE=0;"
708//      Note I_exp_orig,"BOX=0;SPLINE=0;"
709//     
710//      //add data to the graph
711        Execute "AppendConcatenated()"
712       
713        SetDataFolder root:
714End
715
716// remove any q-values <= val
717Function RemoveBadQPoints(qw,iw,sw,val)
718        Wave qw,iw,sw
719        Variable val
720       
721        Variable ii,num,numBad,qval
722        num = numpnts(qw)
723       
724        ii=0
725        numBad=0
726        do
727                qval = qw[ii]
728                if(qval <= val)
729                        numBad += 1
730                else            //keep the points
731                        qw[ii-numBad] = qval
732                        iw[ii-numBad] = iw[ii]
733                        sw[ii-numBad] = sw[ii]
734                endif
735                ii += 1
736        while(ii<num)
737        //trim the end of the waves
738        DeletePoints num-numBad, numBad, qw,iw,sw
739        return(numBad)
740end
741
742// if mw = Nan, keep the point, if a numerical value, delete it
743Function RemoveMaskedPoints(mw,qw,iw,sw)
744        Wave mw,qw,iw,sw
745       
746        Variable ii,num,numBad,mask
747        num = numpnts(qw)
748       
749        ii=0
750        numBad=0
751        do
752                mask = mw[ii]
753                if(numtype(mask) != 2)          //if not NaN
754                        numBad += 1
755                else            //keep the points that are NaN
756                        qw[ii-numBad] = qw[ii]
757                        iw[ii-numBad] = iw[ii]
758                        sw[ii-numBad] = sw[ii]
759                endif
760                ii += 1
761        while(ii<num)
762        //trim the end of the waves
763        DeletePoints num-numBad, numBad, qw,iw,sw
764        return(numBad)
765end
766
767// produces the _msk waves that have the new number of data points
768//
769Function C1D_MaskDoneButton(ctrlName) : ButtonControl
770        String ctrlName
771
772
773        Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
774        if(!aExists)
775                return(1)               //possibly reverted data, no cursor, no Mask wave
776        endif
777       
778        Duplicate/O $(ksCombine1DFolder+":Q_exp_orig"),$(ksCombine1DFolder+":Q_msk")
779        Duplicate/O $(ksCombine1DFolder+":I_exp_orig"),$(ksCombine1DFolder+":I_msk")
780        Duplicate/O $(ksCombine1DFolder+":S_exp_orig"),$(ksCombine1DFolder+":S_msk")
781        Wave Q_msk=$(ksCombine1DFolder+":Q_msk")
782        Wave I_msk=$(ksCombine1DFolder+":I_msk")
783        Wave S_msk=$(ksCombine1DFolder+":S_msk")
784       
785        //finish up - trim the data sets and reassign the working set
786        Wave MaskData=$(ksCombine1DFolder+":MaskData")
787       
788        RemoveMaskedPoints(MaskData,Q_msk,I_msk,S_msk)
789
790        //reset the number of points
791        NVAR gNq = $(ksCombine1DFolder+":gNq")
792        gNq = numpnts(Q_msk)
793       
794        Cursor/K A
795        HideInfo
796       
797        return(0)
798End
799
800
801// not quite the same as revert
802Function C1D_ClearMaskProc(ctrlName) : ButtonControl
803        String ctrlName
804       
805        SetDataFolder $ksCombine1DFolder
806       
807        Wave Q_exp_orig
808        Duplicate/O Q_exp_orig MaskData
809        MaskData = NaN          //use all data
810                       
811        SetDataFolder root:
812
813        return(0)
814end
815
816// when the mask tab is selected, A must be on the graph
817// Displays MaskData wave on the graph
818//
819Function C1D_MyMaskProc(ctrlName) : ButtonControl
820        String ctrlName
821       
822       
823        Wave data=$(ksCombine1DFolder+":I_exp_orig")
824       
825        SetDataFolder $ksCombine1DFolder
826       
827        Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
828               
829        if(aExists)             //mask the selected point
830                // toggle NaN (keep) or Data value (= masked)
831                Wave MaskData
832                MaskData[pcsr(A)] = (numType(MaskData[pcsr(A)])==0) ? NaN : data[pcsr(A)]               //if NaN, doesn't plot
833        else
834                Wave I_exp_orig,Q_exp_orig
835                Cursor /A=1/H=1/L=1/P/W=V_Combine_1D_Graph A I_exp_orig leftx(I_exp_orig)
836                ShowInfo
837                //if the mask wave does not exist, make one
838                if(exists("MaskData") != 1)
839                        Duplicate/O Q_exp_orig MaskData
840                        MaskData = NaN          //use all data
841                endif
842                Execute "AppendMask()" 
843        endif
844
845        SetDataFolder root:
846
847        return(0)
848End
849
850// when the mask button is pressed, A must be on the graph
851// Displays MaskData wave on the graph
852//
853Function C1D_MaskLTCursor(ctrlName) : ButtonControl
854        String ctrlName
855
856               
857        Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
858       
859        if(!aExists)
860                return(1)
861        endif
862// need to get rid of old smoothed data if data is re-masked
863//      Execute "RemoveSmoothed()"
864//      SetDataFolder $(ksCombine1DFolder)
865//      Killwaves/Z I_smth,Q_smth,S_smth
866
867        SetDataFolder $(ksCombine1DFolder)
868
869        Wave data=I_exp_orig
870
871        Variable pt,ii
872        pt = pcsr(A)
873        for(ii=pt;ii>=0;ii-=1)
874                // toggle NaN (keep) or Data value (= masked)
875                Wave MaskData
876                MaskData[ii] = (numType(MaskData[ii])==0) ? NaN : data[ii]              //if NaN, doesn't plot
877        endfor
878
879        SetDataFolder root:
880        return(0)
881End
882
883// when the mask button is pressed, A must be on the graph
884// Displays MaskData wave on the graph
885//
886Function C1D_MaskGTCursor(ctrlName) : ButtonControl
887        String ctrlName
888       
889        Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
890       
891        if(!aExists)
892                return(1)
893        endif
894// need to get rid of old smoothed data if data is re-masked
895//      Execute "RemoveSmoothed()"
896//      SetDataFolder $(ksCombine1DFolder)
897//      Killwaves/Z I_smth,Q_smth,S_smth
898
899        SetDataFolder $(ksCombine1DFolder)
900
901        Wave data=I_exp_orig
902       
903        Wave MaskData
904
905        Variable pt,ii,endPt
906        endPt=numpnts(MaskData)
907        pt = pcsr(A)
908        for(ii=pt;ii<endPt;ii+=1)
909                // toggle NaN (keep) or Data value (= masked)
910                Wave MaskData
911                MaskData[ii] = (numType(MaskData[ii])==0) ? NaN : data[ii]              //if NaN, doesn't plot
912        endfor
913
914        SetDataFolder root:
915
916        return(0)
917End
918
919// when the mask button is pressed, A must be on the graph
920// Displays MaskData wave on the graph
921//
922Function C1D_MaskPercent(ctrlName) : ButtonControl
923        String ctrlName
924       
925        Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
926       
927        if(!aExists)
928                return(1)
929        endif
930
931
932        SetDataFolder $(ksCombine1DFolder)
933
934        Wave data=I_exp_orig
935        Wave s_orig = S_exp_orig
936        Wave MaskData
937
938
939        Variable pct,ii,endPt
940        endPt=numpnts(MaskData)
941
942        pct = 0.05
943       
944        for(ii=0;ii<endPt;ii+=1)
945                // toggle NaN (keep) or Data value (= masked)
946
947                MaskData[ii] = (abs(s_orig[ii]/data[ii]) < pct) ? NaN : data[ii]                //if NaN, doesn't plot
948        endfor
949
950
951        SetDataFolder root:
952
953        return(0)
954End
955
956
957
958
959Function CleanUpJunk()
960
961        // clean up the old junk on the graph, /Z for no error
962        // TODO:
963        // -- activate both of these functions to clean old data off of the graph
964//      Execute "RemoveOldData()"
965        Execute "RemoveMask()"
966       
967        //remove the cursor
968        Cursor/K A
969       
970        //always re-initialize these
971        String/G $(ksCombine1DFolder+":gStr1") = ""
972
973        // clean up the old waves from smoothing and desmearing steps
974        SetDataFolder $(ksCombine1DFolder)
975        Killwaves/Z MaskData,Q_msk,I_msk,S_msk
976        SetDataFolder root:
977End
978
979
980
981// I_dsm is the desmeared data
982//
983// step (7) - desmearing is done, write out the result
984//
985Function C1D_SaveButtonProc(ctrlName) : ButtonControl
986        String ctrlName
987
988
989        String saveStr
990        SVAR curFile = $(ksCombine1DFolder+":gCurFile")
991        saveStr = CleanupName((curFile),0)              //the output filename
992        //
993
994        V_Write_VSANSMasked1D(saveStr,0,0,1)                    //use the full set (lo=hi=0) and present a dialog
995       
996        SetDataFolder root:
997        return(0)
998End
999
1000Function C1D_HelpButtonProc(ctrlName) : ButtonControl
1001        String ctrlName
1002
1003        DisplayHelpTopic/Z/K=1 "Combining VSANS Data"
1004        if(V_flag !=0)
1005                DoAlert 0,"The Combining VSANS Data Help file could not be found"
1006        endif
1007        return(0)
1008End
1009
1010
1011//toggles the log/lin display of the loaded data set
1012Function C1D_LoadCheckProc(ctrlName,checked) : CheckBoxControl
1013        String ctrlName
1014        Variable checked
1015
1016        ModifyGraph log=(checked)
1017        return(0)
1018End
1019
1020
1021
1022
1023
1024// TODO:
1025// -- either update this to be correct for VSANS, or dispatch to some other data writer.
1026//
1027Function V_Write_VSANSMasked1D(fullpath,lo,hi,dialog)
1028        String fullpath
1029        Variable lo,hi,dialog           //=1 will present dialog for name
1030       
1031       
1032        String termStr="\r\n"
1033        String destStr = ksCombine1DFolder
1034        String formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr
1035       
1036        Variable refNum,integer,realval
1037       
1038        //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error****
1039        WAVE Q_msk=$(destStr + ":Q_msk")
1040        WAVE I_msk=$(destStr + ":I_msk")
1041        WAVE S_msk=$(destStr + ":S_msk")
1042       
1043        //check each wave
1044        If(!(WaveExists(Q_msk)))
1045                Abort "Q_msk DNExist in WriteUSANSDesmeared()"
1046        Endif
1047        If(!(WaveExists(I_msk)))
1048                Abort "I_msk DNExist in WriteUSANSDesmeared()"
1049        Endif
1050        If(!(WaveExists(S_msk)))
1051                Abort "S_msk DNExist in WriteUSANSDesmeared()"
1052        Endif
1053       
1054        // TODO:
1055        // -- this remnant from desmearing creates fake resolution waves!!!
1056        // -- correctly handle the input resolution waves
1057        // make dummy waves to hold the "fake" resolution, and write it as the last 3 columns
1058        //
1059        Duplicate/O Q_msk,res1,res2,res3
1060        res3 = 1                // "fake" beamstop shadowing
1061        res1 /= 100             //make the sigmaQ so small that there is no smearing
1062       
1063        if(dialog)
1064                Open/D refnum as fullpath+".cmb"                //won't actually open the file
1065                If(cmpstr(S_filename,"")==0)
1066                        //user cancel, don't write out a file
1067                        Close/A
1068                        Abort "no data file was written"
1069                Endif
1070                fullpath = S_filename
1071        Endif
1072       
1073        //write out partial set?
1074        Duplicate/O Q_msk,tq,ti,te
1075        ti=I_msk
1076        te=S_msk
1077        if( (lo!=hi) && (lo<hi))
1078                redimension/N=(hi-lo+1) tq,ti,te,res1,res2,res3         //lo to hi, inclusive
1079                tq=Q_msk[p+lo]
1080                ti=I_msk[p+lo]
1081                te=S_msk[p+lo]
1082        endif
1083       
1084        //tailor the output given the type of data written out...
1085        String samStr="",dateStr="",str1,str2
1086
1087       
1088        samStr = fullpath
1089        dateStr="CREATED: "+date()+" at  "+time()
1090
1091
1092       
1093        //actually open the file
1094        Open refNum as fullpath
1095       
1096        fprintf refnum,"%s"+termStr,samStr
1097//      fprintf refnum,"%s"+termStr,str1
1098//      fprintf refnum,"%s"+termStr,str2
1099        fprintf refnum,"%s"+termStr,dateStr
1100       
1101        wfprintf refnum, formatStr, tq,ti,te,res1,res2,res3
1102       
1103        Close refnum
1104       
1105        Killwaves/Z ti,tq,te,res1,res2,res3
1106       
1107        Return(0)
1108End
1109
1110
1111
1112
1113Function V_GetScalingInOverlap(num2,wave1q,wave1i,wave2q,wave2i)
1114        Variable num2           //largest point number of wave2 in overlap region
1115        Wave wave1q,wave1i,wave2q,wave2i                //1 = first dataset, 2= second dataset
1116
1117        Variable ii,ival1,newi,ratio
1118        ratio=0
1119        ii=0
1120        do
1121                //get scaling factor at each point of wave 2 in the overlap region
1122                newi = interp(wave2q[ii],wave1q,wave1i)         //get the intensity of wave1 at an overlap point
1123                ratio += newi/wave2i[ii]                                        //get the scale factor
1124                //Print "ratio = ",ratio
1125                ii+=1
1126        while(ii<=num2)
1127        Variable val
1128        val = ratio/(num2+1)            // +1 counts for point zero
1129        //Print "val = ",val
1130
1131        Variable tol=1.05                       //5% is the preferred number (for Andrew and Lionel, at least)
1132
1133//      ControlInfo/W=NSORT_Panel WarningCheck
1134//      if(( V_Value==1 ) && ( (val > tol) || (val < 1/tol) ) )
1135//              String str=""
1136//              sprintf str,"The scaling factor is more than a factor of %g from 1. Proceed with caution.\r",tol
1137//              DoAlert 0,str
1138//      endif
1139       
1140        Return val
1141End
Note: See TracBrowser for help on using the repository browser.