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

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

First pass at routines to interactively combine and mask VSANS 1-D data sets. Based on masking as done in the USANS Desmearing panel.

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