source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Subtract_1D.ipf @ 683

Last change on this file since 683 was 618, checked in by srkline, 13 years ago

fixing simple typos

File size: 19.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5///////////////////////
6//
7// Procedures to manipulate 1-D datasets
8// specifically, to subtract 1-D data (sample - buffer)
9// as is typically done for biological samples in buffer solution
10//
11// This was written largely by Dobrin Bossev
12// - I simply adapted it to work cleanly with the SANS Reduction Macros
13// - 14MAY03 SRK
14//
15//
16// - could be expanded to do more manipulations, but could quickly
17// become cumbersome (like the Arithmetic Panel)
18//
19// - could allow for interpolation to match data sets, or only a partial
20// q-range for the "solvent" file
21//
22///////////////////////
23
24// main entry procedure for subtraction panel
25// re-initializes necessary folders and waves
26Proc OpenSubtract1DPanel()
27        DoWindow/F Subtract_1D_Panel
28        if(V_Flag==0)
29                Init_Subtract1D()
30                Subtract_1D()           //the panel
31                Plot_Sub1D()            //the graph
32        endif
33End
34
35// initializes data folder and waves needed for the panel (contains a listbox)
36Proc Init_Subtract1D()
37        //create the data folder
38        NewDataFolder/O/S root:myGlobals:Subtract1D
39        //create the waves and variables
40        String/G gName1="<none>"
41        String/G gName2="<none>"
42        Variable/G gSolvnormal=0
43        Variable/G gPresetc=0
44        Variable/G gS1=0
45        Variable/G gS2=0
46        Variable/G gCorrection=1
47        Variable/G gPlotState=0
48        Variable/G gNullSolvent=0
49               
50        Make/N=1/D/O w01,w11,w21,w31,w41,w51
51        Make/N=1/D/O w02,w12,w22,w32,w42,w52
52        Duplicate/O w01 xsample
53        Duplicate/O w11 ysample
54        Duplicate/O w21 ssample
55        Duplicate/O w02 xsolvent
56        Duplicate/O w12 ysolvent
57        Duplicate/O w22 ssolvent
58        Duplicate/O w01 xresult
59        Duplicate/O w11 yresult
60        Duplicate/O w21 sresult
61       
62        SetDataFolder root:
63End
64
65//draws the panel to control the subtraction
66Proc Subtract_1D()
67        if(root:myGlobals:gIsMac==1)
68                NewPanel /W=(467,139,821,423)/K=2  as "Solvent Subtraction"
69        else
70                NewPanel /W=(522,139,876,422)/K=2  as "Solvent Subtraction"
71        endif
72        DoWindow/C Subtract_1D_Panel
73        SetDrawEnv fsize=10, fstyle= 5,textrgb=(65535,0,0)
74        DrawText 10,20,"Sample Scattering File:"
75        SetDrawEnv textrgb= (0,0,65280),fstyle=5,fsize=10
76        DrawText 10,90,"Solvent Scattering File:"
77        SetDrawEnv  fsize=10, fstyle= 5
78        DrawText 10,165,"Result:"
79        //add the controls
80        Button button_0,pos={150,36},size={90,20},proc=LoadSample, title="Load Sample"
81        Button button_0,help={"This will load the 6 column Sample Scattering File"}
82        Button button_1,pos={150,106},size={90,20},proc=LoadSolvent,title="Load Solvent"
83        Button button_1,help={"This will load the 6 column Solvent Scattering File"}
84        Button button_4,pos={18,248},size={90,20},proc=Calculate,title="Calculate"
85        Button button_4,help={"This will subtract the intensities of the two files according to the shown expression"}
86        Button button_5,pos={122,248},size={110,20},proc=SaveResult,title="Save Result"
87        Button button_5,help={"This will save the result in a file"}
88        Button button_6,pos={10,196},size={125,20},proc=MatchingRange,title="Matching Range"
89        Button button_6,help={"This will capture the range between the two cursors to determine f"}
90        Button button_2,pos={275,248},size={50,20},proc=Sub1D_DoneButton,title="Done"
91        Button button_2,help={"Closes both the panel and the associated graph"}
92        Button button_3,pos={300,36},size={25,20},proc=ShowSub1DHelp,title="?"
93        Button button_3,help={"Shows help file for subtracting 1-D data sets"}
94        CheckBox check_0,pos={14,40},size={117,14},proc=CheckCon,title="Rescale Sample file?"
95        CheckBox check_0,value= root:myGlobals:Subtract1D:gSolvnormal
96        CheckBox check_1,pos={235,187},size={134,14},proc=CheckCon,title="Preset     manually?"
97        CheckBox check_1,value= root:myGlobals:Subtract1D:gPresetc
98        CheckBox check_2,pos={225,150},size={134,14},proc=NullSolventCheck,title="Solvent = 1?"
99        CheckBox check_2,value= root:myGlobals:Subtract1D:gNullSolvent,disable=2
100        //
101        ValDisplay valdisp_0,pos={145,187},size={70,18},title="Start ",Font="Arial",fsize=10
102        ValDisplay valdisp_0,limits={0,0,0},barmisc={0,1000},value= root:myGlobals:Subtract1D:gS1
103        ValDisplay valdisp_1,pos={145,207},size={70,18},title="End  ",Font="Arial",fsize=10
104        ValDisplay valdisp_1,limits={0,0,0},barmisc={0,1000},value= root:myGlobals:Subtract1D:gS2
105        //
106        SetVariable setvar_0,pos={250,207},size={70,19},title=":",font="Arial",fsize=10
107        SetVariable setvar_0,limits={-inf,inf,0},value=root:myGlobals:Subtract1D:gCorrection
108        //sample name
109        SetVariable setvar_1,pos={150,7},size={200,20},title=":",noEdit=1
110        SetVariable setvar_1,limits={1,1,0},value=root:myGlobals:Subtract1D:gName1
111        //solvent name
112        SetVariable setvar_2,pos={150,77},size={200,20},title=":",noEdit=1
113        SetVariable setvar_2,limits={1,1,0},value=root:myGlobals:Subtract1D:gName2
114        //
115        SetDrawEnv fname="Times", fsize=14, fstyle= 3
116        DrawText 289,202,"f"
117        SetDrawEnv fname="Times", fsize=14, fstyle= 3
118        DrawText 241,223,"f"
119        //draw the fancy text on the panel
120        WriteExpression(0)
121       
122EndMacro
123
124Function ShowSub1DHelp(ctrlName) : ButtonControl
125        String ctrlName
126        DisplayHelpTopic/Z/K=1 "SANS Data Reduction Tutorial[Subtract 1D Data]"
127        if(V_flag !=0)
128                DoAlert 0,"The SANS Data Reduction Tutorial Help file could not be found"
129        endif
130End
131//kills both the panel and the graph, and then the data folder
132Function Sub1D_DoneButton(ctrlName)
133        String ctrlName
134       
135        DoWindow/K Subtract_1D_Panel
136        DoWindow/K Plot_Sub1D
137        KillDataFolder root:myGlobals:Subtract1D
138        return(0)
139End
140
141
142Function Calculate(ctrlName) : ButtonControl
143        String ctrlName
144
145//      SetDataFolder root:myGlobals:Subtract1D
146        Variable p1,p2
147        SVAR gName1 = root:myGlobals:Subtract1D:gName1
148        SVAR gName2 = root:myGlobals:Subtract1D:gName2
149        //check for files
150        if(cmpstr(gName2,"<none>") == 0)
151                DoAlert 0, "Load Solvent file!"
152                return(1)
153        endif
154        if(cmpstr(gName1,"<none>") == 0)
155                DoAlert 0, "Load Sample file!"
156                return(1)
157        endif
158       
159        WAVE xsample=root:myGlobals:Subtract1D:xsample
160        WAVE xsolvent=root:myGlobals:Subtract1D:xsolvent
161        //WAVE w01=root:myGlobals:Subtract1D:w01
162        WAVE ysample=root:myGlobals:Subtract1D:ysample          //w11
163        WAVE ssample=root:myGlobals:Subtract1D:ssample          //w21
164        WAVE ysolvent=root:myGlobals:Subtract1D:ysolvent                        //w12
165        WAVE ssolvent=root:myGlobals:Subtract1D:ssolvent                        //w22
166       
167        NVAR gPresetc = root:myGlobals:Subtract1D:gPresetc
168        NVAR gSolvNormal = root:myGlobals:Subtract1D:gSolvNormal
169        NVAR gCorrection = root:myGlobals:Subtract1D:gCorrection
170        NVAR gNullSolvent = root:myGlobals:Subtract1D:gNullSolvent
171        NVAR gS1 = root:myGlobals:Subtract1D:gS1
172        NVAR gS2 = root:myGlobals:Subtract1D:gS2
173
174//no interpolation - exit if files are not EXACTLY the same length
175// and have EXACTLY the same q-values
176//
177////////////// 
178//      Variable maxDiff
179//      //check that both files are of the same length
180//      if (numpnts(xsample)!=numpnts(xsolvent))
181//              DoAlert 0, "The lengths of Sample and Solvent files are NOT identical!"
182//              return(1)
183//      endif
184//     
185//      //check that both files have the same q-values
186//      //currently, abort, but could offer to interpolate
187//      Duplicate/O xsample helpwave
188//      helpwave = 100*abs((xsample - xsolvent)/xsample)                //% difference in q-values
189//      WaveStats /Q helpwave
190//      KillWaves /Z helpwave
191//      maxDiff = V_max
192//      if(maxDiff > 0.5)               //each q-value must match to within 0.5%
193//              DoAlert 0, "The q-values of Sample and Solvent files are NOT identical!"
194//              return(1)
195//      endif
196///////////////
197       
198        //set up for interpolation
199        Duplicate/O xsample root:myGlobals:Subtract1D:xsolv_interp      //make the solvent x match the sample
200        Duplicate/O xsample root:myGlobals:Subtract1D:ysolv_interp
201        Duplicate/O xsample root:myGlobals:Subtract1D:ssolv_interp
202        WAVE xsolv_interp = root:myGlobals:Subtract1D:xsolv_interp
203        WAVE ysolv_interp = root:myGlobals:Subtract1D:ysolv_interp
204        WAVE ssolv_interp = root:myGlobals:Subtract1D:ssolv_interp
205        ysolv_interp = interp(xsolv_interp, xsolvent, ysolvent )
206        ssolv_interp = interp(xsolv_interp, xsolvent, ssolvent )
207       
208        Duplicate/O xsample root:myGlobals:Subtract1D:xresult
209        Duplicate/O ysample root:myGlobals:Subtract1D:yresult
210        Duplicate/O ssample root:myGlobals:Subtract1D:sresult
211        WAVE xresult = root:myGlobals:Subtract1D:xresult
212        WAVE yresult = root:myGlobals:Subtract1D:yresult
213        WAVE sresult = root:myGlobals:Subtract1D:sresult
214       
215        if (gPresetc==0)                //find the constant from the cursor range
216                Duplicate/O ysample helpwave
217                if(gSolvNormal && gNullSolvent)
218                        helpWave = ysample                              //ysolvent == 0 under these conditions
219                else
220                        helpwave = ysample/ysolv_interp         //get the ratio = I(sample)/I(solvent)
221                endif
222                //gS1 and gS2 are qvalues now, convert them back to points
223                //on the interpolated xsolv_interp
224                p1 = BinarySearch(xsolv_interp, gS1 )
225                p2 = BinarySearch(xsolv_interp, gS2 )
226                //print p1,p2
227                WaveStats/Q/R=[p1,p2] helpwave          //just in the selected range
228                gCorrection = V_avg
229                KillWaves /Z helpwave
230        endif
231        if (gSolvnormal==0)
232                yresult = ysample - gCorrection*ysolv_interp
233                sresult = sqrt(ssample^2+gCorrection*gCorrection*ssolv_interp^2)
234        else
235                yresult = ysample/gCorrection - ysolv_interp
236                sresult = sqrt((ssample^2)/gCorrection/gCorrection+ssolv_interp^2)
237        endif
238        return(0)
239End
240
241Proc LoadSample(ctrlName) : ButtonControl
242        String ctrlName
243       
244        LoadFile_Sub1D(1)
245        SetDataFolder root:myGlobals:Subtract1D
246        Duplicate/O w01 xsample
247        Duplicate/O w11 ysample
248        Duplicate/O w21 ssample
249        SetDataFolder root:
250       
251        //allow user to set unity/null background, now that sample data exists
252        CheckBox check_2 win=Subtract_1D_Panel,disable=0
253        //if solvent was set to one (or zero), toggle the box so the
254        //"solvent" set is updated to reflect the q-values of the newly
255        //loaded sample
256        ControlInfo check_2
257        if(V_Value==1)
258                NullSolventCheck("",1)          //fakes as if the box was checked
259        Endif
260       
261End
262
263
264Proc LoadSolvent(ctrlName) : ButtonControl
265        String ctrlName
266
267        LoadFile_Sub1D(2)
268        SetDataFolder root:myGlobals:Subtract1D
269        Duplicate/O w02 xsolvent
270        Duplicate/O w12 ysolvent
271        Duplicate/O w22 ssolvent
272       
273        if (cmpstr(gName2,"<none>")!=0)
274                Cursor A, ysolvent, leftx(xsolvent)
275                Cursor/A=0 B, ysolvent, rightx(xsolvent)
276                //make sure that the "solvent ==1" checkbox is not checked
277                CheckBox check_2,value=0
278                //MatchingRange("none")
279        endif
280        SetDataFolder root:
281End
282
283//returns the Matching range to use in terms of q-values
284//rather than points, which will be incorrect if the
285//solvent data needs to be interpolated
286Function MatchingRange(ctrlName) : ButtonControl
287        String ctrlName
288
289        SVAR name2 = root:myGlobals:Subtract1D:gName2
290        NVAR s1 = root:myGlobals:Subtract1D:gS1
291        NVAR s2 = root:myGlobals:Subtract1D:gS2
292        if (cmpstr(name2,"<none>") != 0)
293                s1=min(pcsr(A,"Plot_Sub1D" ),pcsr(B,"Plot_Sub1D"))
294                s2=max(pcsr(A,"Plot_Sub1D" ),pcsr(B,"Plot_Sub1D"))
295                Wave qval=root:myGlobals:Subtract1D:xsolvent            //this will exist
296                s1 = qval[s1]
297                s2 = qval[s2]
298                //print s1,s2
299        endif
300End
301
302Proc Plot_Sub1D()
303        SetDataFolder root:myGlobals:Subtract1D
304        if(root:myGlobals:gIsMac==1)
305                Display/W=(14,44,454,484)/K=1 ysample vs xsample
306        else
307                Display/W=(14,44,350,380)/K=1 ysample vs xsample
308        endif
309        DoWindow/C Plot_Sub1D
310        ModifyGraph rgb(ysample)=(65535,0,0)
311        ErrorBars/T=0 ysample Y,wave=(ssample,ssample)
312        AppendToGraph/L ysolvent vs xsolvent
313        ModifyGraph rgb(ysolvent)=(0,0,65535)
314        ErrorBars/T=0 ysolvent Y,wave=(ssolvent,ssolvent)
315        //AppendToGraph/R yresult vs xresult
316        AppendToGraph/L yresult vs xresult
317        ModifyGraph rgb(yresult)=(0,65535,0)
318        ErrorBars/T=0 yresult Y,wave=(sresult,sresult)
319        ModifyGraph mode=3, msize=2, marker=19, mirror=1, tick=2, log(bottom)=1
320        Legend/C/N=text0/J/A=LT/X=2/Y=2 "\\s(ysample) Sample\r\\s(ysolvent) Solvent\r\\s(yresult) Result"
321        ShowInfo
322        Label left "Sample, Solvent I (cm\\S-1\M)"
323        Label bottom "q ("+root:myGlobals:gAngstStr+"\\S-1\M)"
324//      Label right "Result I/cm\\S-1"
325        ControlBar 40
326        Button button_7,pos={10,10},size={125,20},proc=MatchingRange,title="Matching Range"
327        Button button_7,help={"This will capture the range between the two cursors to determine f"}
328        CheckBox check_0,pos={170,12},size={117,14},proc=PlotSub1DCheck,title="Log I(q)?"
329        CheckBox check_0,value= root:myGlobals:Subtract1D:gPlotState
330        SetDataFolder root:
331End
332
333//toggles the y-axis scaling of the graph between log and linear
334// the bottom axis is always log scale
335//
336Proc PlotSub1DCheck(ctrlName,checked) : CheckBoxControl
337        String ctrlName
338        Variable checked
339
340        SetdataFolder root:myGlobals:Subtract1D
341        if(checked)
342                //make log scale
343                ModifyGraph log=1
344        else
345                //make linear scale on y-axis
346                Modifygraph log=0,log(bottom)=1
347        endif
348        gPlotState = checked
349        SetDataFolder root:
350End
351
352//
353Proc NullSolventCheck(ctrlName,checked) : CheckBoxControl
354        String ctrlName
355        Variable checked
356
357        SetDataFolder root:myGlobals:Subtract1D
358       
359        Variable solvValue
360        String nameStr=""
361        if(gSolvNormal)
362                CheckBox check_2,title="Solvent = 0?"
363                solvValue=0
364                nameStr="Solvent values set to zero"
365        else
366                CheckBox check_2,title="Solvent = 1?"
367                solvValue=1
368                nameStr="Solvent value set to one"
369        endif
370       
371        if(checked)
372                //zero/one for the solvent
373                Duplicate/O w01 xsolvent                //duplicate the sample data
374                Duplicate/O w11 ysolvent
375                Duplicate/O w21 ssolvent
376                ysolvent=solvValue
377                ssolvent=0
378                if(gS1==0 && gS2 ==0)
379                        Cursor A, ysample, leftx(xsample)       // put the cursors on the sample data
380                        Cursor/A=0 B, ysample, rightx(xsample)
381                else
382                        Cursor A, ysample, BinarySearch(xsample, gS1 )          // put the cursors on the sample data
383                        Cursor/A=0 B, ysample, BinarySearch(xsample, gS2 )
384                endif
385                gName2 = nameStr
386        else
387                gName2 = "<none>"
388        Endif
389        gNullSolvent=checked
390       
391        SetDataFolder root:
392End
393
394Proc CheckCon(ctrlName,checked) : CheckBoxControl
395        String ctrlName
396        Variable checked
397
398        SetdataFolder root:myGlobals:Subtract1D
399        if (cmpstr(ctrlName,"check_0") == 0)            //box to set the normalization
400                gSolvnormal =checked
401                WriteExpression(checked)                //draw the text of the expression being calculated
402                ControlInfo check_2
403                NullSolventCheck("",V_Value)
404        else
405                //check_1,      box to manually set the preset
406          gPresetc = checked
407        endif
408        SetDataFolder root:
409End
410
411//type = 1 specifies sample data
412//type = 2 specifies solvent data
413//
414// any existing data will be overwritten
415//
416// need to retain header information for later save
417// will need a more sophisticated open/close to get the header
418//
419//don't try to re-write as a function - not worth the effort
420//
421Proc LoadFile_Sub1D(type)
422        Variable type   
423       
424        String n0,n1,n2,n3,n4,n5,help
425       
426        Variable refnum,numLines,numData,numHdr,ii
427        String fileStr="",junkStr=""
428       
429        //junkStr = PadString(junkStr, 100, 0 )
430        fileStr=DoOpenFileDialog("pick a 1D data set")
431        if(cmpstr(fileStr,"")==0)
432                return          //no file selected, exit
433        endif
434       
435        SetDataFolder root:myGlobals:Subtract1D
436        LoadWave/G/D/A fileStr
437        If (V_flag==6)
438                n0 = StringFromList(0, S_waveNames ,";" )
439                n1 = StringFromList(1, S_waveNames ,";" )
440                n2 = StringFromList(2, S_waveNames ,";" )
441                n3 = StringFromList(3, S_waveNames ,";" )
442                n4 = StringFromList(4, S_waveNames ,";" )
443                n5 = StringFromList(5, S_waveNames ,";" )
444                Duplicate/O $n0, $("w0" + num2istr(type))
445                Duplicate/O $n1, $("w1" + num2istr(type))
446                Duplicate/O $n2, $("w2" + num2istr(type))
447                Duplicate/O $n3, $("w3" + num2istr(type))
448                Duplicate/O $n4, $("w4" + num2istr(type))
449                Duplicate/O $n5, $("w5" + num2istr(type))
450                if (type==1)
451                        gName1 = S_fileName
452                        //read in the header of the sample file
453                        // not yet implemented
454                        numLines = CountNumLines(fileStr)
455                        numData = numpnts($n0)
456                        numHdr = numLines - numData
457                        Make/T/O/N=(numHdr) SampleHeader
458                        Open/R refNum as fileStr
459                        ii=0
460                        do
461                                FReadLine refnum, junkStr
462                                SampleHeader[ii] = junkStr
463                                ii+=1
464                        while(ii<numHdr)
465                        Close refnum
466                else
467                        gName2 = S_fileName
468                endif
469       
470        elseif (V_flag == 4)
471                n0 = StringFromList(0, S_waveNames ,";" )
472                n1 = StringFromList(1, S_waveNames ,";" )
473                n2 = StringFromList(2, S_waveNames ,";" )
474                n3 = StringFromList(3, S_waveNames ,";" )
475                Duplicate/O $n0, $("w0" + num2istr(type))
476                Duplicate/O $n1, $("w1" + num2istr(type))
477                Duplicate/O $n2, $("w2" + num2istr(type))
478                Duplicate/O $n3, $("w3" + num2istr(type))
479                if (type==1)
480                        gName1 = S_fileName
481                        //read in the header of the sample file
482                        // not yet implemented
483                        numLines = CountNumLines(fileStr)
484                        numData = numpnts($n0)
485                        numHdr = numLines - numData
486                        Make/T/O/N=(numHdr) SampleHeader
487                        Open/R refNum as fileStr
488                        ii=0
489                        do
490                                FReadLine refnum, junkStr
491                                SampleHeader[ii] = junkStr
492                                ii+=1
493                        while(ii<numHdr)
494                        Close refnum
495                else
496                        gName2 = S_fileName
497                endif
498               
499        elseif (V_flag == 3)
500                n0 = StringFromList(0, S_waveNames ,";" )
501                n1 = StringFromList(1, S_waveNames ,";" )
502                n2 = StringFromList(2, S_waveNames ,";" )
503                Duplicate/O $n0, $("w0" + num2istr(type))
504                Duplicate/O $n1, $("w1" + num2istr(type))
505                Duplicate/O $n2, $("w2" + num2istr(type))
506                if (type==1)
507                        gName1 = S_fileName
508                        //read in the header of the sample file
509                        // not yet implemented
510                        numLines = CountNumLines(fileStr)
511                        numData = numpnts($n0)
512                        numHdr = numLines - numData
513                        Make/T/O/N=(numHdr) SampleHeader
514                        Open/R refNum as fileStr
515                        ii=0
516                        do
517                                FReadLine refnum, junkStr
518                                SampleHeader[ii] = junkStr
519                                ii+=1
520                        while(ii<numHdr)
521                        Close refnum
522                else
523                        gName2 = S_fileName
524                endif
525        else
526                if (V_flag>0)
527                        DoAlert 0, "This is NOT a 3-, 4- or 6-column file !"
528                endif
529        endif
530        //do some cleanup
531       
532        KillWaves/Z wave0,wave1,wave2,wave3,wave4,wave5,wave6,wave7,wave8,wave9,wave10
533       
534        setDataFolder root:
535end
536
537Function CountNumLines(fileStr)
538        String fileStr
539       
540        Variable num,refnum
541        num=0
542        Open/R refNum as fileStr
543        do
544                FReadLine refnum, junkStr
545                FStatus refnum
546//              Print junkStr
547                num+=1
548        while(V_FilePos<V_logEOF)
549//      print "numlines = ",num
550        Close refnum
551        return(num)
552End
553
554
555Function SaveResult(ctrlName) : ButtonControl
556        String ctrlName
557
558        WAVE xresult = root:myGlobals:Subtract1D:xresult
559        WAVE yresult = root:myGlobals:Subtract1D:yresult
560        WAVE sresult = root:myGlobals:Subtract1D:sresult
561        WAVE w31 = root:myGlobals:Subtract1D:w31
562        WAVE w41 = root:myGlobals:Subtract1D:w41
563        WAVE w51 = root:myGlobals:Subtract1D:w51
564        WAVE/T hdr = root:myGlobals:Subtract1D:SampleHeader
565       
566        //check each wave for existence
567        Variable err=0,refnum
568        String fileName=""
569        String formatStr = ""
570        if (WaveExists(w41) && WaveExists(w51))
571                //6-column
572                formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"
573        elseif(WaveExists(w31))
574                //4-column (ILL)
575                formatStr = "%15.4g %15.4g %15.4g %15.4g\r\n"
576        else
577                //3-column
578                formatStr = "%15.4g %15.4g %15.4g\r\n"
579        endif
580        err += 1 - WaveExists(xresult)
581        err += 1 - WaveExists(yresult)
582        err += 1 - WaveExists(sresult)
583        //err += 1 - WaveExists(w31)
584        //err += 1 - WaveExists(w41)
585        //err += 1 - WaveExists(w51)
586        err += 1 - WaveExists(hdr)
587       
588        if(err>0)
589                DoAlert 0,"We need at least 3 column data - I can't write out the file"
590                return(1)
591        endif
592       
593        SVAR loadedFile=root:myGlobals:Subtract1D:gName1
594        fileName = DoSaveFileDialog("Save Data as",fname=loadedFile,suffix="b")
595        if(cmpstr(fileName,"")==0)
596                return(1)
597        endif
598        Open refNum as fileName
599        wfprintf refnum,"%s\n",hdr              //strings already have \r?
600        if (WaveExists(w41) && WaveExists(w51))
601                wfprintf refnum, formatStr, xresult,yresult,sresult,w31,w41,w51
602        elseif (WaveExists(w31))
603                wfprintf refnum, formatStr, xresult,yresult,sresult,w31
604        else
605                wfprintf refnum,formatStr, xresult,yresult,sresult
606        endif
607        Close refnum
608       
609        return(0)
610End
611
612Proc WriteExpression(choice)
613        Variable choice
614
615        SetDrawEnv /W=Subtract_1D_Panel linefgc= (65535,65535,65535)
616        DrawRect 90,140,207,174
617        SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0)
618        DrawText 100,168,"I"
619        SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0)
620        DrawText 100,168,"  ="
621        SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0)
622        DrawText 100,168,"     I"
623        SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535)
624        DrawText 100,168,"              I"
625        if (choice==0)
626                SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0)
627                DrawText 100,168,"       -"
628                SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0)
629                DrawText 100,168,"          f "
630                SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0)
631                DrawText 100,168,"            *"
632        else
633                SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0)
634                DrawText 100,168,"       /"
635                SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0)
636                DrawText 100,168,"         f "
637                SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0)
638                DrawText 100,168,"           -"
639        endif
640End
Note: See TracBrowser for help on using the repository browser.