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

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

changes for combining of 1D data sets

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