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

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

made the file selections in the test protocol panel to be popup menus with the filtered files for each step. popping now selects the file. Still a work in progress.

File size: 24.0 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// TODO:
19// x- add a popup to the load tab to set the work folder
20// x- add this file to the Includes list and to the SVN folder
21// -- add button (mask tab) to save mask
22// -- add button (mask tab) to recall mask
23// -- think of ways to run through the files batchwise (instead of adding this to the protocol)
24// -- link the main entry procedure to the main panel
25//
26// -- when do I concatenate the data sets?
27// ---- do I add a concatenate button to the Load tab, then this single set is the
28//    starting point for the MASK tab
29// ---- the Load Data button could then be a loader for a single file, which is then the "concatenated"
30//     starting point...
31//
32// x- make the graph larger for easier viewing of the data
33// -- increase the size of the tab control, rearrange the other controls
34//
35// -- how do I incorporate the rescaling?
36//
37// -- error bars on the graph
38// x- legend on the graph
39//
40// x- define a new folder for all of this -- NOT the protocol folder
41// x- define a string constant with this path
42//
43// -- button to mask based on relative error threshold for each data point. may be a good startng point for
44//    masking
45//
46// -- remove the mask by relative error button - this is not really a good idea.
47//
48//
49
50
51StrConstant ksCombine1DFolder = "root:Packages:NIST:VSANS:Globals:Combine_1D"
52
53// main entry routine
54Macro V_Combine_1D()
55
56        //check for the correct folder, initialize if necessary
57        //
58        if(DataFolderExists(ksCombine1DFolder) == 0)
59                Execute "V_Init_Combine_1D()"
60        endif
61       
62        SetDataFolder root:
63       
64        DoWindow/F V_Combine_1D_Graph
65        if(V_flag==0)
66                Execute "V_Combine_1D_Graph()"
67        endif
68End
69
70Proc V_Init_Combine_1D()
71
72        //set up the folder(s) needed
73        NewDataFolder/O $(ksCombine1DFolder)
74       
75        SetDataFolder $(ksCombine1DFolder)
76       
77        String/G gCurFile=""
78        String/G gStr1=""
79        Variable/G gFreshMask=1
80        Variable/G gNq=0
81       
82        SetDataFolder root:
83End
84
85
86////
87//
88//
89Proc V_Combine_1D_Graph()
90
91        PauseUpdate; Silent 1           // building window...
92        Display /W=(699,45,1328,779) /K=1
93        ModifyGraph cbRGB=(51664,44236,58982)
94        ModifyGraph tickUnit=1
95        DoWindow/C V_Combine_1D_Graph
96        ControlBar 160
97        // break into tabs
98        TabControl C1D_Tab,pos={5,3},size={392,128},proc=C1D_TabProc
99        TabControl C1D_Tab,labelBack=(49151,49152,65535),tabLabel(0)="Load"
100        TabControl C1D_Tab,tabLabel(1)="Mask",tabLabel(2)="Rescale",value=0
101       
102        //always visible - revert and save
103        //maybe the wrong place here?
104        Button C1DControlA,pos={225,135},size={80,20},proc=C1D_RevertButtonProc,title="Revert"
105        Button C1DControlA,help={"Revert the data to its original state and start over"}
106        Button C1DControlB,pos={325,135},size={50,20},proc=C1D_SaveButtonProc,title="Save"
107        Button C1DControlB,help={"Save the masked and scaled data set"}
108        Button C1DControlC,pos={25,135},size={50,20},proc=C1D_HelpButtonProc,title="Help"
109        Button C1DControlC,help={"Show the help file for combining VSANS data sets"}
110       
111        // add the controls to each tab ---- all names start with "C1DControl_"
112
113        //tab(0) Load - initially visible
114        Button C1DControl_0a,pos={23,39},size={80,20},proc=C1D_LoadButtonProc,title="Load Data"
115        Button C1DControl_0a,help={"Load slit-smeared USANS data = \".cor\" files"}
116        CheckBox C1DControl_0b,pos={26,74},size={80,14},proc=C1D_LoadCheckProc,title="Log Axes?"
117        CheckBox C1DControl_0b,help={"Toggle Log/Lin Q display"},value= 1
118        TitleBox C1DControl_0c,pos={120,37},size={104,19},font="Courier",fSize=10
119        TitleBox C1DControl_0c,variable= $(ksCombine1DFolder+":gStr1")
120        PopupMenu C1DControl_0d,pos={120,75},size={71,20},title="Bin Type"
121        PopupMenu C1DControl_0d,help={"This popup selects how the y-axis will be linearized based on the chosen data"}
122        PopupMenu C1DControl_0d,value= "One;Two;Four;Slit Mode;"
123        PopupMenu C1DControl_0d,mode=1,proc=V_CombineModePopup
124        PopupMenu C1DControl_0e,pos={120,100},size={109,20},title="Data Source"
125        PopupMenu C1DControl_0e,mode=1,popvalue="RAW",value= #"\"RAW;SAM;EMP;BGD;COR;ABS;\""           
126        Button C1DControl_0f,pos={200,39},size={120,20},proc=C1D_ConcatButtonProc,title="Concatenate"
127        Button C1DControl_0f,help={"Load slit-smeared USANS data = \".cor\" files"}
128
129       
130        //tab(1) Mask
131        Button C1DControl_1a,pos={20,35},size={90,20},proc=C1D_MyMaskProc,title="Mask Point"            //bMask
132        Button C1DControl_1a,help={"Toggles the masking of the selected data point"}
133        Button C1DControl_1a,disable=1
134        Button C1DControl_1b,pos={20,65},size={140,20},proc=C1D_MaskGTCursor,title="Mask Q >= Cursor"           //bMask
135        Button C1DControl_1b,help={"Toggles the masking of all q-values GREATER than the current cursor location"}
136        Button C1DControl_1b,disable=1
137        Button C1DControl_1c,pos={20,95},size={140,20},proc=C1D_MaskLTCursor,title="Mask Q <= Cursor"           //bMask
138        Button C1DControl_1c,help={"Toggles the masking of all q-values LESS than the current cursor location"}
139        Button C1DControl_1c,disable=1
140        Button C1DControl_1d,pos={180,35},size={90,20},proc=C1D_ClearMaskProc,title="Clear Mask"                //bMask
141        Button C1DControl_1d,help={"Clears all mask points"}
142        Button C1DControl_1d,disable=1
143        Button C1DControl_1e,pos={180,65},size={90,20},proc=C1D_MaskPercent,title="Percent Mask"                //bMask
144        Button C1DControl_1e,help={"Clears all mask points"}
145        Button C1DControl_1e,disable=1
146       
147       
148//      Button C1DControl_1b,pos={144,66},size={110,20},proc=C1D_MaskDoneButton,title="Done Masking"
149//      Button C1DControl_1b,disable=1
150       
151//      //tab(2) Rescale
152        Button C1DControl_2a,pos={31,42},size={90,20},proc=C1D_ExtrapolateButtonProc,title="Extrapolate"
153        Button C1DControl_2a,help={"Extrapolate the high-q region with a power-law"}
154        Button C1DControl_2a,disable=1
155        SetVariable C1DControl_2b,pos={31,70},size={100,15},title="# of points"
156        SetVariable C1DControl_2b,help={"Set the number of points for the power-law extrapolation"}
157        SetVariable C1DControl_2b,limits={5,100,1},value=_NUM:123
158        SetVariable C1DControl_2b,disable=1
159        CheckBox C1DControl_2c,pos={157,45},size={105,14},proc=C1D_ExtrapolationCheckProc,title="Show Extrapolation"
160        CheckBox C1DControl_2c,help={"Show or hide the high q extrapolation"},value= 1
161        CheckBox C1DControl_2c,disable=1
162        SetVariable C1DControl_2d,pos={31,96},size={150,15},title="Power Law Exponent"
163        SetVariable C1DControl_2d,help={"Power Law exponent from the fit = the DESMEARED slope - override as needed"}
164        SetVariable C1DControl_2d format="%5.2f"
165        SetVariable C1DControl_2d,limits={-inf,inf,0},value=_NUM:123
166        SetVariable C1DControl_2d,disable=1
167       
168        Legend/C/N=text0/J/X=72.00/Y=60.00
169
170       
171        SetDataFolder root:
172EndMacro
173
174//
175// recalculate the I(q) binning. no need to adjust model function or views
176// just rebin
177//
178// see V_BinningModePopup() in V_DataPlotting.ipf for a duplicate verison of this function
179Function V_CombineModePopup(ctrlName,popNum,popStr) : PopupMenuControl
180        String ctrlName
181        Variable popNum // which item is currently selected (1-based)
182        String popStr           // contents of current popup item as string
183
184// TODO
185// x- replace the type with selection from the panel - don't use the current display type
186        ControlInfo C1DControl_0e
187        String type = S_Value
188
189        SVAR gStr1 = $(ksCombine1DFolder+":gStr1")
190        gStr1 = type
191       
192       
193        V_QBinAllPanels(type,popNum)
194
195
196        String str,winStr="V_Combine_1D_Graph"
197        sprintf str,"(\"%s\",%d,\"%s\")",type,popNum,winStr
198
199// TODO:
200// x- replace these calls -- they work with the 1d plot, not this panel. I want them to do basically the same
201//    exact things, but with a different target window
202//  *** these calls now take the target window as a parameter - so that there is only one version
203        Execute ("V_Back_IQ_Graph"+str)
204        Execute ("V_Middle_IQ_Graph"+str)
205        Execute ("V_Front_IQ_Graph"+str)
206               
207       
208        return(0)       
209End
210
211
212// function to control the drawing of buttons in the TabControl on the main panel
213// Naming scheme for the buttons MUST be strictly adhered to... else buttons will
214// appear in odd places...
215// all buttons are named C1DControl_NA where N is the tab number and A is the letter denoting
216// the button's position on that particular tab.
217// in this way, buttons will always be drawn correctly :-)
218//
219Function C1D_TabProc(ctrlName,tab) //: TabControl
220        String ctrlName
221        Variable tab
222
223        String ctrlList = ControlNameList("",";"),item="",nameStr=""
224        Variable num = ItemsinList(ctrlList,";"),ii,onTab
225        for(ii=0;ii<num;ii+=1)
226                //items all start w/"C1DControl_"               //11 characters
227                item=StringFromList(ii, ctrlList ,";")
228                nameStr=item[0,10]
229                if(cmpstr(nameStr,"C1DControl_")==0)
230                        onTab = str2num(item[11])                       //12th is a number
231                        ControlInfo $item
232                        switch(abs(V_flag))     
233                                case 1:
234                                        Button $item,disable=(tab!=onTab)
235                                        break
236                                case 2:
237                                        CheckBox $item,disable=(tab!=onTab)
238                                        break
239                                case 5:
240                                        SetVariable $item,disable=(tab!=onTab)
241                                        break
242                                case 10:       
243                                        TitleBox $item,disable=(tab!=onTab)
244                                        break
245                                case 4:
246                                        ValDisplay $item,disable=(tab!=onTab)
247                                        break
248                                case 3:
249                                        PopupMenu $item,disable=(tab!=onTab)
250                                        break
251                                // add more items to the switch if different control types are used
252                        endswitch
253                       
254                endif
255        endfor
256       
257        // remove the mask if I go back to the data?
258        if(tab==0)
259                RemoveMask()
260//              RemoveConcatenated()
261        endif
262       
263        // masking
264        if(tab==1)
265                C1D_ClearMaskProc("")           //starts with a blank mask
266                C1D_MyMaskProc("")              //start masking if you click on the tab
267        else
268                C1D_MaskDoneButton("")          //masking is done if you click off the tab
269        endif
270       
271        // rescaling
272        if(tab == 2)
273        // TODO
274        // -- fill this in
275        // -- this is still in the thought process at this point
276       
277// do rescaling of the different sections of the data set
278               
279        endif
280       
281        return 0
282End
283
284
285Proc AppendConcatenated()
286
287        if( strsearch(TraceNameList("V_Combine_1D_Graph", "", 1),"I_exp_orig",0,2) == -1)                       //Igor 5
288                SetDataFolder $(ksCombine1DFolder)
289                AppendToGraph/W=V_Combine_1D_Graph I_exp_orig vs Q_exp_orig
290                ModifyGraph mode(I_exp_orig)=3,marker(I_exp_orig)=19,msize(I_exp_orig)=2,opaque(I_exp_orig)=1
291                ModifyGraph rgb(I_exp_orig)=(0,0,0)
292               
293                ModifyGraph tickUnit=1,log=1
294                Modifygraph grid=1,mirror=2
295
296                ErrorBars/T=0 I_exp_orig Y,wave=(S_exp_orig,S_exp_orig)
297               
298                setdatafolder root:
299        endif
300end
301
302Function RemoveConcatenated()
303
304        SetDataFolder $(ksCombine1DFolder)
305        RemoveFromGraph/W=V_Combine_1D_Graph/Z I_exp_orig
306        setdatafolder root:
307end
308
309Proc AppendMask()
310
311        if( strsearch(TraceNameList("V_Combine_1D_Graph", "", 1),"MaskData",0,2) == -1)                 //Igor 5
312                SetDataFolder $(ksCombine1DFolder)
313                AppendToGraph/W=V_Combine_1D_Graph MaskData vs Q_exp_orig
314                ModifyGraph mode(MaskData)=3,marker(MaskData)=8,msize(MaskData)=2.5,opaque(MaskData)=1
315                ModifyGraph rgb(MaskData)=(65535,16385,16385)
316               
317                setdatafolder root:
318        endif
319end
320
321
322
323Function RemoveMask()
324
325        SetDataFolder $(ksCombine1DFolder)
326        RemoveFromGraph/W=V_Combine_1D_Graph/Z MaskData
327        setdatafolder root:
328end
329
330
331// concatenate the data, and replace the multiple data sets with the concatenated set
332// - then you can proceed to the mask tab
333//
334Function C1D_ConcatButtonProc(ctrlName) : ButtonControl
335        String ctrlName
336
337
338        ControlInfo C1DControl_0e
339        String folderStr = S_Value
340
341        SVAR gStr1 = $(ksCombine1DFolder+":gStr1")
342        gStr1 = folderStr
343
344
345        ControlInfo C1DControl_0d
346        Variable binType = V_Value
347       
348        V_1DConcatenate(folderStr,binType)
349
350// sort the data set
351        V_TmpSort1D(folderStr)
352       
353// now copy the concatenated data over to the combine folder   
354        Duplicate/O $("root:Packages:NIST:VSANS:"+folderStr+":tmp_q") $(ksCombine1DFolder+":Q_exp")             
355        Duplicate/O $("root:Packages:NIST:VSANS:"+folderStr+":tmp_i") $(ksCombine1DFolder+":I_exp")             
356        Duplicate/O $("root:Packages:NIST:VSANS:"+folderStr+":tmp_s") $(ksCombine1DFolder+":S_exp")     
357        wave Q_exp = $(ksCombine1DFolder+":Q_exp")
358        Wave I_exp = $(ksCombine1DFolder+":I_exp")
359        Wave S_exp = $(ksCombine1DFolder+":S_exp")
360       
361
362//     
363        Duplicate/O $(ksCombine1DFolder+":Q_exp") $(ksCombine1DFolder+":Q_exp_orig")
364        Duplicate/O $(ksCombine1DFolder+":I_exp") $(ksCombine1DFolder+":I_exp_orig")
365        Duplicate/O $(ksCombine1DFolder+":S_exp") $(ksCombine1DFolder+":S_exp_orig")
366        wave I_exp_orig = $(ksCombine1DFolder+":I_exp_orig")
367       
368        Variable nq = numpnts($(ksCombine1DFolder+":Q_exp"))
369//     
370
371//      // append the (blank) wave note to the intensity wave
372//      Note I_exp,"BOX=0;SPLINE=0;"
373//      Note I_exp_orig,"BOX=0;SPLINE=0;"
374//     
375//      //add data to the graph
376        Execute "AppendConcatenated()" 
377       
378        // TODO:
379        // -- do I clear off the old data here, or somewhere else?
380        // clear off the old data from the individual panels
381        // use ClearAllIQIfDisplayed()
382        ClearIQIfDisplayed_AllBin(folderStr,"V_Combine_1D_Graph")
383
384        RemoveMask()
385       
386        return(0)
387End
388
389// step (1) - get the data from a WORK folder, and plot it
390// clear out all of the "old" waves, remove them from the graph first
391//
392// ??produces Q_exp, I_exp, S_exp waves (and originals "_orig")
393// add a dummy wave note that can be changed on later steps
394//
395Function C1D_LoadButtonProc(ctrlName) : ButtonControl
396        String ctrlName
397
398
399        String qStr,iStr,sStr,sqStr
400        Variable nq,dqv,numBad,val
401       
402        // remove any of the old traces on the graph and delete the waves and reset the global strings
403        CleanUpJunk()
404       
405        SetDataFolder root:
406       
407        // go get the new data
408        Execute "A_LoadOneDDataWithName(\"\",0)"
409
410// TODO:       
411        // x-Missing something here from the loader - go back to the LakeDesmearing ipf
412        SVAR fname = root:Packages:NIST:gLastFileName           //this is the 1D file loaded
413
414//     
415        qStr = CleanupName((fName + "_q"),0)            //the q-wave
416        iStr = CleanupName((fName + "_i"),0)            //the i-wave
417        sStr = CleanupName((fName + "_s"),0)            //the s-wave
418//      sqStr = CleanupName((fName + "sq"),0)           //the sq-wave
419//
420        String DFStr= CleanupName(fname,0)
421//     
422        Duplicate/O $("root:"+DFStr+":"+qStr) $(ksCombine1DFolder+":Q_exp")             
423        Duplicate/O $("root:"+DFStr+":"+iStr) $(ksCombine1DFolder+":I_exp")             
424        Duplicate/O $("root:"+DFStr+":"+sStr) $(ksCombine1DFolder+":S_exp")     
425        wave Q_exp = $(ksCombine1DFolder+":Q_exp")
426        Wave I_exp = $(ksCombine1DFolder+":I_exp")
427        Wave S_exp = $(ksCombine1DFolder+":S_exp")
428       
429
430//     
431        Duplicate/O $(ksCombine1DFolder+":Q_exp") $(ksCombine1DFolder+":Q_exp_orig")
432        Duplicate/O $(ksCombine1DFolder+":I_exp") $(ksCombine1DFolder+":I_exp_orig")
433        Duplicate/O $(ksCombine1DFolder+":S_exp") $(ksCombine1DFolder+":S_exp_orig")
434        wave I_exp_orig = $(ksCombine1DFolder+":I_exp_orig")
435       
436        nq = numpnts($(ksCombine1DFolder+":Q_exp"))
437//     
438
439//      // append the (blank) wave note to the intensity wave
440//      Note I_exp,"BOX=0;SPLINE=0;"
441//      Note I_exp_orig,"BOX=0;SPLINE=0;"
442//     
443//      //add data to the graph
444        Execute "AppendConcatenated()"
445       
446        SetDataFolder root:
447End
448
449// remove any q-values <= val
450Function RemoveBadQPoints(qw,iw,sw,val)
451        Wave qw,iw,sw
452        Variable val
453       
454        Variable ii,num,numBad,qval
455        num = numpnts(qw)
456       
457        ii=0
458        numBad=0
459        do
460                qval = qw[ii]
461                if(qval <= val)
462                        numBad += 1
463                else            //keep the points
464                        qw[ii-numBad] = qval
465                        iw[ii-numBad] = iw[ii]
466                        sw[ii-numBad] = sw[ii]
467                endif
468                ii += 1
469        while(ii<num)
470        //trim the end of the waves
471        DeletePoints num-numBad, numBad, qw,iw,sw
472        return(numBad)
473end
474
475// if mw = Nan, keep the point, if a numerical value, delete it
476Function RemoveMaskedPoints(mw,qw,iw,sw)
477        Wave mw,qw,iw,sw
478       
479        Variable ii,num,numBad,mask
480        num = numpnts(qw)
481       
482        ii=0
483        numBad=0
484        do
485                mask = mw[ii]
486                if(numtype(mask) != 2)          //if not NaN
487                        numBad += 1
488                else            //keep the points that are NaN
489                        qw[ii-numBad] = qw[ii]
490                        iw[ii-numBad] = iw[ii]
491                        sw[ii-numBad] = sw[ii]
492                endif
493                ii += 1
494        while(ii<num)
495        //trim the end of the waves
496        DeletePoints num-numBad, numBad, qw,iw,sw
497        return(numBad)
498end
499
500// produces the _msk waves that have the new number of data points
501//
502Function C1D_MaskDoneButton(ctrlName) : ButtonControl
503        String ctrlName
504
505
506        Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
507        if(!aExists)
508                return(1)               //possibly reverted data, no cursor, no Mask wave
509        endif
510       
511        Duplicate/O $(ksCombine1DFolder+":Q_exp_orig"),$(ksCombine1DFolder+":Q_msk")
512        Duplicate/O $(ksCombine1DFolder+":I_exp_orig"),$(ksCombine1DFolder+":I_msk")
513        Duplicate/O $(ksCombine1DFolder+":S_exp_orig"),$(ksCombine1DFolder+":S_msk")
514        Wave Q_msk=$(ksCombine1DFolder+":Q_msk")
515        Wave I_msk=$(ksCombine1DFolder+":I_msk")
516        Wave S_msk=$(ksCombine1DFolder+":S_msk")
517       
518        //finish up - trim the data sets and reassign the working set
519        Wave MaskData=$(ksCombine1DFolder+":MaskData")
520       
521        RemoveMaskedPoints(MaskData,Q_msk,I_msk,S_msk)
522
523        //reset the number of points
524        NVAR gNq = $(ksCombine1DFolder+":gNq")
525        gNq = numpnts(Q_msk)
526       
527        Cursor/K A
528        HideInfo
529       
530        return(0)
531End
532
533
534// not quite the same as revert
535Function C1D_ClearMaskProc(ctrlName) : ButtonControl
536        String ctrlName
537       
538        SetDataFolder $ksCombine1DFolder
539       
540        Wave Q_exp_orig
541        Duplicate/O Q_exp_orig MaskData
542        MaskData = NaN          //use all data
543                       
544        SetDataFolder root:
545
546        return(0)
547end
548
549// when the mask tab is selected, A must be on the graph
550// Displays MaskData wave on the graph
551//
552Function C1D_MyMaskProc(ctrlName) : ButtonControl
553        String ctrlName
554       
555       
556        Wave data=$(ksCombine1DFolder+":I_exp_orig")
557       
558        SetDataFolder $ksCombine1DFolder
559       
560        Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
561               
562        if(aExists)             //mask the selected point
563                // toggle NaN (keep) or Data value (= masked)
564                Wave MaskData
565                MaskData[pcsr(A)] = (numType(MaskData[pcsr(A)])==0) ? NaN : data[pcsr(A)]               //if NaN, doesn't plot
566        else
567                Wave I_exp_orig,Q_exp_orig
568                Cursor /A=1/H=1/L=1/P/W=V_Combine_1D_Graph A I_exp_orig leftx(I_exp_orig)
569                ShowInfo
570                //if the mask wave does not exist, make one
571                if(exists("MaskData") != 1)
572                        Duplicate/O Q_exp_orig MaskData
573                        MaskData = NaN          //use all data
574                endif
575                Execute "AppendMask()" 
576        endif
577
578        SetDataFolder root:
579
580        return(0)
581End
582
583// when the mask button is pressed, A must be on the graph
584// Displays MaskData wave on the graph
585//
586Function C1D_MaskLTCursor(ctrlName) : ButtonControl
587        String ctrlName
588
589               
590        Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
591       
592        if(!aExists)
593                return(1)
594        endif
595// need to get rid of old smoothed data if data is re-masked
596//      Execute "RemoveSmoothed()"
597//      SetDataFolder $(ksCombine1DFolder)
598//      Killwaves/Z I_smth,Q_smth,S_smth
599
600        SetDataFolder $(ksCombine1DFolder)
601
602        Wave data=I_exp_orig
603
604        Variable pt,ii
605        pt = pcsr(A)
606        for(ii=pt;ii>=0;ii-=1)
607                // toggle NaN (keep) or Data value (= masked)
608                Wave MaskData
609                MaskData[ii] = (numType(MaskData[ii])==0) ? NaN : data[ii]              //if NaN, doesn't plot
610        endfor
611
612        SetDataFolder root:
613        return(0)
614End
615
616// when the mask button is pressed, A must be on the graph
617// Displays MaskData wave on the graph
618//
619Function C1D_MaskGTCursor(ctrlName) : ButtonControl
620        String ctrlName
621       
622        Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
623       
624        if(!aExists)
625                return(1)
626        endif
627// need to get rid of old smoothed data if data is re-masked
628//      Execute "RemoveSmoothed()"
629//      SetDataFolder $(ksCombine1DFolder)
630//      Killwaves/Z I_smth,Q_smth,S_smth
631
632        SetDataFolder $(ksCombine1DFolder)
633
634        Wave data=I_exp_orig
635       
636        Wave MaskData
637
638        Variable pt,ii,endPt
639        endPt=numpnts(MaskData)
640        pt = pcsr(A)
641        for(ii=pt;ii<endPt;ii+=1)
642                // toggle NaN (keep) or Data value (= masked)
643                Wave MaskData
644                MaskData[ii] = (numType(MaskData[ii])==0) ? NaN : data[ii]              //if NaN, doesn't plot
645        endfor
646
647        SetDataFolder root:
648
649        return(0)
650End
651
652// when the mask button is pressed, A must be on the graph
653// Displays MaskData wave on the graph
654//
655Function C1D_MaskPercent(ctrlName) : ButtonControl
656        String ctrlName
657       
658        Variable aExists= strlen(CsrInfo(A)) > 0                        //Igor 5
659       
660        if(!aExists)
661                return(1)
662        endif
663
664
665        SetDataFolder $(ksCombine1DFolder)
666
667        Wave data=I_exp_orig
668        Wave s_orig = S_exp_orig
669        Wave MaskData
670
671
672        Variable pct,ii,endPt
673        endPt=numpnts(MaskData)
674
675        pct = 0.05
676       
677        for(ii=0;ii<endPt;ii+=1)
678                // toggle NaN (keep) or Data value (= masked)
679
680                MaskData[ii] = (abs(s_orig[ii]/data[ii]) < pct) ? NaN : data[ii]                //if NaN, doesn't plot
681        endfor
682
683
684        SetDataFolder root:
685
686        return(0)
687End
688
689
690
691
692Function CleanUpJunk()
693
694        // clean up the old junk on the graph, /Z for no error
695        // TODO:
696        // -- activate both of these functions to clean old data off of the graph
697//      Execute "RemoveOldData()"
698        Execute "RemoveMask()"
699       
700        //remove the cursor
701        Cursor/K A
702       
703        //always re-initialize these
704        String/G $(ksCombine1DFolder+":gStr1") = ""
705
706        // clean up the old waves from smoothing and desmearing steps
707        SetDataFolder $(ksCombine1DFolder)
708        Killwaves/Z MaskData,Q_msk,I_msk,S_msk
709        SetDataFolder root:
710End
711
712
713
714// I_dsm is the desmeared data
715//
716// step (7) - desmearing is done, write out the result
717//
718Function C1D_SaveButtonProc(ctrlName) : ButtonControl
719        String ctrlName
720
721
722        String saveStr
723        SVAR curFile = $(ksCombine1DFolder+":gCurFile")
724        saveStr = CleanupName((curFile),0)              //the output filename
725        //
726
727        V_Write_VSANSMasked1D(saveStr,0,0,1)                    //use the full set (lo=hi=0) and present a dialog
728       
729        SetDataFolder root:
730        return(0)
731End
732
733Function C1D_HelpButtonProc(ctrlName) : ButtonControl
734        String ctrlName
735
736        DisplayHelpTopic/Z/K=1 "Combining VSANS Data"
737        if(V_flag !=0)
738                DoAlert 0,"The Combining VSANS Data Help file could not be found"
739        endif
740        return(0)
741End
742
743
744//toggles the log/lin display of the loaded data set
745Function C1D_LoadCheckProc(ctrlName,checked) : CheckBoxControl
746        String ctrlName
747        Variable checked
748
749        ModifyGraph log=(checked)
750        return(0)
751End
752
753
754
755
756
757// TODO:
758// -- either update this to be correct for VSANS, or dispatch to some other data writer.
759//
760Function V_Write_VSANSMasked1D(fullpath,lo,hi,dialog)
761        String fullpath
762        Variable lo,hi,dialog           //=1 will present dialog for name
763       
764       
765        String termStr="\r\n"
766        String destStr = ksCombine1DFolder
767        String formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr
768       
769        Variable refNum,integer,realval
770       
771        //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error****
772        WAVE Q_msk=$(destStr + ":Q_msk")
773        WAVE I_msk=$(destStr + ":I_msk")
774        WAVE S_msk=$(destStr + ":S_msk")
775       
776        //check each wave
777        If(!(WaveExists(Q_msk)))
778                Abort "Q_msk DNExist in WriteUSANSDesmeared()"
779        Endif
780        If(!(WaveExists(I_msk)))
781                Abort "I_msk DNExist in WriteUSANSDesmeared()"
782        Endif
783        If(!(WaveExists(S_msk)))
784                Abort "S_msk DNExist in WriteUSANSDesmeared()"
785        Endif
786       
787        // TODO:
788        // -- this remnant from desmearing creates fake resolution waves!!!
789        // -- correctly handle the input resolution waves
790        // make dummy waves to hold the "fake" resolution, and write it as the last 3 columns
791        //
792        Duplicate/O Q_msk,res1,res2,res3
793        res3 = 1                // "fake" beamstop shadowing
794        res1 /= 100             //make the sigmaQ so small that there is no smearing
795       
796        if(dialog)
797                Open/D refnum as fullpath+".cmb"                //won't actually open the file
798                If(cmpstr(S_filename,"")==0)
799                        //user cancel, don't write out a file
800                        Close/A
801                        Abort "no data file was written"
802                Endif
803                fullpath = S_filename
804        Endif
805       
806        //write out partial set?
807        Duplicate/O Q_msk,tq,ti,te
808        ti=I_msk
809        te=S_msk
810        if( (lo!=hi) && (lo<hi))
811                redimension/N=(hi-lo+1) tq,ti,te,res1,res2,res3         //lo to hi, inclusive
812                tq=Q_msk[p+lo]
813                ti=I_msk[p+lo]
814                te=S_msk[p+lo]
815        endif
816       
817        //tailor the output given the type of data written out...
818        String samStr="",dateStr="",str1,str2
819
820       
821        samStr = fullpath
822        dateStr="CREATED: "+date()+" at  "+time()
823
824
825       
826        //actually open the file
827        Open refNum as fullpath
828       
829        fprintf refnum,"%s"+termStr,samStr
830//      fprintf refnum,"%s"+termStr,str1
831//      fprintf refnum,"%s"+termStr,str2
832        fprintf refnum,"%s"+termStr,dateStr
833       
834        wfprintf refnum, formatStr, tq,ti,te,res1,res2,res3
835       
836        Close refnum
837       
838        Killwaves/Z ti,tq,te,res1,res2,res3
839       
840        Return(0)
841End
842
843
844
845
846Function V_GetScalingInOverlap(num2,wave1q,wave1i,wave2q,wave2i)
847        Variable num2           //largest point number of wave2 in overlap region
848        Wave wave1q,wave1i,wave2q,wave2i                //1 = first dataset, 2= second dataset
849
850        Variable ii,ival1,newi,ratio
851        ratio=0
852        ii=0
853        do
854                //get scaling factor at each point of wave 2 in the overlap region
855                newi = interp(wave2q[ii],wave1q,wave1i)         //get the intensity of wave1 at an overlap point
856                ratio += newi/wave2i[ii]                                        //get the scale factor
857                //Print "ratio = ",ratio
858                ii+=1
859        while(ii<=num2)
860        Variable val
861        val = ratio/(num2+1)            // +1 counts for point zero
862        //Print "val = ",val
863
864        Variable tol=1.05                       //5% is the preferred number (for Andrew and Lionel, at least)
865
866//      ControlInfo/W=NSORT_Panel WarningCheck
867//      if(( V_Value==1 ) && ( (val > tol) || (val < 1/tol) ) )
868//              String str=""
869//              sprintf str,"The scaling factor is more than a factor of %g from 1. Proceed with caution.\r",tol
870//              DoAlert 0,str
871//      endif
872       
873        Return val
874End
Note: See TracBrowser for help on using the repository browser.