source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Transmission.ipf @ 794

Last change on this file since 794 was 794, checked in by srkline, 12 years ago

Lots of changes:
-2D resolution smearing
-2D error propagation

1) 2D resolution smearing has been corrected to use sigma (perp) correctly
rather than phi. This shows up in the quadrature loop in all of the 2D models
and in the Smear_2D "generic" function.

2) 1D resolutionn smearing is now corrected to account for the integration
range of +/- 3 sigma (99.73% of distribution). Now the result is divided by
0.9973 to rescale it to the correct value.

3) Smeared models are now AAO to improve speed and to allow easier use with
functions that are inherently AAO. No changes are needed, since the call is
behind the scenes, replacing Smear_Model_N() with Smear_Model_N_AAO().

4) in PlotUtils_2D added functions to re-bin the QxQy? data into a 1D format
BinQxQy_to_1D(). This also re-bins the errors in two ways, adding the per-pixel
errors in quadrature, or the deviation from the mean of the intensity. Manually
editing the intensity declaration allows 2D->1D binning of smeared models.

5) Per-pixel propagation of errors has been added through the entire data
reduction sequence. Data errors are generated on loading using Poisson
statistics (specifically tailored for accuracy at low counts) and then is
propagated through each manipulation of the data using standard error
propagation. The error matrix is linear_data_error. As a by-product, all of
the math operations on data are explicitly done on linear_data, to avoid
any potential mistakes of log/linear scaling. Results of this propagation
largely match J. Barker's /ERROR routines from the VAX, with some differences
at low data count values (as expected) and at higher count values near the
beam stop (somewhat unexpected). This per-pixel error is ouput in the QxQy_ASCII
data files. NO CHANGE has been made to the 1D data, which uses the deviation from
the mean as the error - since this is correct.

6) Added tables for the uncertainty in attenuator transmission (from JGB)

7) added two more REAL values to the VAX header to store information
necessary for error propagation. These are couting error that are part of
the transmission error and of the absolute scaling error. These add Read/Write?
functions in NCNR_DataReadWrite

The transmission error (one standard deviation) is written at byte 396 (4 bytes)

RealsRead?[41]

The Box Sum error (one standard deviation) is written at byte 400 (4 bytes)

RealsRead?[42]

File size: 77.5 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5//*************************
6// Vers. 1.2 092101
7//
8// - procedures for (easier) caluclation of transmissions along with
9//  simultaneous patching of the calculated transmission in designated
10//  raw sans files.
11// - transmission and empty beam files are linked to the dataset by their "Annn" suffix
12//   only (and their residence in the same data folder)
13// - unused (analysis) integer values are used to store these run numbers in the sample
14//   file headers so that transmissions can be automatically calculated, once the xy box is set
15//   in the empty beam file.
16//
17//***************************
18
19//main entry procedure for displaying the Trans input panel
20//also initializes the globals as needed
21//
22Proc CalcTrans()
23       
24        DoWindow/F Trans_Panel
25        If(V_flag == 0)
26                InitializeTransPanel()
27                //draw panel
28                Trans_Panel()
29                AutoPositionWindow/M=1/R=Main_Panel Trans_Panel
30        Endif
31End
32
33// The BuildFileTables routine will build two tables:  one containing the
34// data from the headers of transmission files in the folder and one
35// containing the header data from all other SANS data files.  They will
36// each have the first column empty for, in the case of transmission files,
37// the empty beam file and, in the case of scattering files, the scattering
38// run file name.
39Proc BuildFileTables()
40
41        Variable err
42        PathInfo catPathName
43        if(v_flag==0)
44                err = PickPath()//sets the local path to the data (catPathName)
45                if(err)
46                        Abort "no path to data was selected, no catalog can be made - use PickPath button"
47                Endif
48        Endif
49
50        DoWindow/F TransFileTable
51
52        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Suffices"
53        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
54        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Filenames"
55        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Suffix"
56        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Labels"
57        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_SDD"
58        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Lambda"
59        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Transmission"
60        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Whole"
61        If(V_Flag==0)
62                BuildTransTableWindow()
63                ModifyTable width(:myGlobals:TransHeaderInfo:T_SDD)=40
64                ModifyTable width(:myGlobals:TransHeaderInfo:T_Lambda)=40
65                ModifyTable rgb(:myGlobals:TransHeaderInfo:T_Filenames)=(0,0,65535)
66                ModifyTable width(:myGlobals:TransHeaderInfo:T_Transmission)=60
67                ModifyTable width(:myGlobals:TransHeaderInfo:T_Whole)=60
68               
69                ModifyTable width(Point)=0
70                //ModifyTable width(:myGlobals:TransHeaderInfo:T_Transmission)=40
71        Endif
72       
73        DoWindow/F ScatterFileTable
74        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Suffices"
75        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
76        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Filenames"
77        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Suffix"
78        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Labels"
79        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_SDD"
80        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Lambda"
81        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Transmission"
82        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Trans_Error"
83
84        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Whole"
85        If(V_Flag==0)
86                BuildScatTableWindow()
87                ModifyTable width(:myGlobals:TransHeaderInfo:S_SDD)=40
88                ModifyTable width(:myGlobals:TransHeaderInfo:S_Lambda)=40
89                ModifyTable width(:myGlobals:TransHeaderInfo:S_Transmission)=60
90                ModifyTable rgb(:myGlobals:TransHeaderInfo:S_Filenames)=(0,0,65535)
91               
92                ModifyTable width(Point)=0
93        Endif
94
95        String temp=""
96
97        //get a list of all files in the folder, some will be junk version numbers that don't exist
98        String list,partialName,tempName
99        list = IndexedFile(catPathName,-1,"????")       //get all files in folder
100        Variable numitems,ii,ok
101
102        //remove version numbers from semicolon-delimited list
103        list =  RemoveVersNumsFromList(list)
104
105        numitems = ItemsInList(list,";")
106
107        //loop through all of the files in the list, reading CAT/SHORT information if the file is RAW SANS
108        //***version numbers have been removed***
109        String str,fullName
110        Variable lastPoint
111        ii=0
112
113        do
114                //get current item in the list
115                partialName = StringFromList(ii, list, ";")
116                //get a valid file based on this partialName and catPathName
117                tempName = FindValidFilename(partialName)
118                If(cmpstr(tempName,"")==0)              //a null string was returned
119                        //write to notebook that file was not found
120                        //if string is not a number, report the error
121                        if(str2num(partialName) == NaN)
122                                str = "this file was not found: "+partialName+"\r\r"
123                                //Notebook CatWin,font="Times",fsize=12,text=str
124                        Endif
125                else
126                        //prepend path to tempName for read routine
127                        PathInfo catPathName
128                        FullName = S_path + tempName
129                        //make sure the file is really a RAW data file
130                        ok = CheckIfRawData(fullName)
131                        if (ok)
132                                GetTransHeaderInfoToWave(fullName,tempName)
133                        Endif
134                Endif
135                ii+=1
136        while(ii<numitems)
137        //Now sort them all based on the suffix data
138        SortTransByDate()
139        //Now fill in the filenames of the ones that have already had EMP or TRANS
140        //files associated with them.
141        GetFilenamesFromSuffices()
142
143        //position the windows nicely
144        AutoPositionWindow/M=1/R=TransFileTable  ScatterFileTable
145        DoWindow/F Trans_Panel
146End
147
148//actually creates the table of transmission files
149// - the waves must exist
150//
151Function BuildTransTableWindow()
152        Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
153        Wave/T T_Filenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
154        Wave/T T_Suffix = $"root:myGlobals:TransHeaderInfo:T_Suffix"
155        Wave/T T_Labels = $"root:myGlobals:TransHeaderInfo:T_Labels"
156        Wave   T_SDD = $"root:myGlobals:TransHeaderInfo:T_SDD"
157        Wave   T_Lambda = $"root:myGlobals:TransHeaderInfo:T_Lambda"
158        Wave   T_Transmission = $"root:myGlobals:TransHeaderInfo:T_Transmission"
159        Wave   T_Whole= $"root:myGlobals:TransHeaderInfo:T_Whole"
160       
161        Edit/K=1/W=(30,30,500,250) T_EMP_Filenames, T_Filenames, T_Labels, T_SDD, T_Lambda, T_Transmission, T_Whole as "TransmissionFiles"
162       
163        SetWindow kwTopWin hook=GuessFromTableHook, hookevents=1        // mouse down events
164       
165        String name="TransFileTable"
166        DoWindow/C $name
167
168End
169
170//actually creates the table of scattering files
171// - the waves must exist
172//
173Function BuildScatTableWindow()
174        Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
175        Wave/T S_Filenames = $"root:myGlobals:TransHeaderInfo:S_Filenames"
176        Wave/T S_Suffix = $"root:myGlobals:TransHeaderInfo:S_Suffix"
177        Wave/T S_Labels = $"root:myGlobals:TransHeaderInfo:S_Labels"
178        Wave   S_SDD = $"root:myGlobals:TransHeaderInfo:S_SDD"
179        Wave   S_Lambda = $"root:myGlobals:TransHeaderInfo:S_Lambda"
180        Wave   S_Transmission = $"root:myGlobals:TransHeaderInfo:S_Transmission"
181        Wave   S_GTrans_err =  $"root:myGlobals:TransHeaderInfo:S_Trans_Error"
182
183       
184        Edit/K=1/W=(50,50,520,270) S_TRANS_Filenames, S_Filenames, S_Labels, S_SDD, S_Lambda, S_Transmission, S_GTrans_err as "ScatteringFiles"
185        String name="ScatterFileTable"
186        DoWindow/C $name
187
188End
189
190//sorts each of the tables by date - does this by using the suffix "Annn"
191// which is automatically supplied by the VAX (and can't be changed)
192// - only problem may be "Z999" -> "A001" rollover
193//
194Function SortTransByDate()
195        Wave/T T_GEMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
196        Wave/T T_GSuffices = $"root:myGlobals:TransHeaderInfo:T_Suffices"
197        Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
198        Wave/T T_GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix"
199        Wave/T T_GLabels = $"root:myGlobals:TransHeaderInfo:T_Labels"
200        Wave   T_GSDD = $"root:myGlobals:TransHeaderInfo:T_SDD"
201        Wave   T_GLambda = $"root:myGlobals:TransHeaderInfo:T_Lambda"
202        Wave   T_GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission"
203        Wave   T_Whole= $"root:myGlobals:TransHeaderInfo:T_Whole"
204
205        Wave/T S_GTRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
206        Wave/T S_GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices"
207        Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames"
208        Wave/T S_GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix"
209        Wave/T S_GLabels = $"root:myGlobals:TransHeaderInfo:S_Labels"
210        Wave   S_GSDD = $"root:myGlobals:TransHeaderInfo:S_SDD"
211        Wave   S_GLambda = $"root:myGlobals:TransHeaderInfo:S_Lambda"
212        Wave   S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission"
213        Wave     S_GTrans_err =  $"root:myGlobals:TransHeaderInfo:S_Trans_Error"
214        Wave   S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole"
215       
216        Sort T_GSuffix, T_GEMP_Filenames, T_GSuffix, T_GSuffices, T_GFilenames, T_GLabels, T_GSDD, T_GLambda, T_GTransmission, T_Whole
217        Sort S_GSuffix, S_GTRANS_Filenames, S_GSuffix, S_GSuffices, S_GFilenames, S_GLabels, S_GSDD, S_GLambda, S_GTransmission, S_Whole, S_GTrans_err
218       
219End
220
221// sorts files alphabetically byt the sample label
222// - consistent and descriptive sample labels really pay off here
223//
224Function SortTransByLabel()
225        Wave/T T_GEMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
226        Wave/T T_GSuffices = $"root:myGlobals:TransHeaderInfo:T_Suffices"
227        Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
228        Wave/T T_GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix"
229        Wave/T T_GLabels = $"root:myGlobals:TransHeaderInfo:T_Labels"
230        Wave   T_GSDD = $"root:myGlobals:TransHeaderInfo:T_SDD"
231        Wave   T_GLambda = $"root:myGlobals:TransHeaderInfo:T_Lambda"
232        Wave   T_GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission"
233        Wave   T_Whole= $"root:myGlobals:TransHeaderInfo:T_Whole"
234       
235        Wave/T S_GTRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
236        Wave/T S_GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices"
237        Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames"
238        Wave/T S_GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix"
239        Wave/T S_GLabels = $"root:myGlobals:TransHeaderInfo:S_Labels"
240        Wave   S_GSDD = $"root:myGlobals:TransHeaderInfo:S_SDD"
241        Wave   S_GLambda = $"root:myGlobals:TransHeaderInfo:S_Lambda"
242        Wave   S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission"
243        Wave   S_GTrans_err =  $"root:myGlobals:TransHeaderInfo:S_Trans_Error"
244        Wave   S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole"
245       
246        Sort T_GLabels, T_GEMP_Filenames, T_GSuffix, T_GSuffices, T_GFilenames, T_GLabels, T_GSDD, T_GLambda, T_GTransmission, T_Whole
247        Sort S_GLabels, S_GTRANS_Filenames, S_GSuffix, S_GSuffices, S_GFilenames, S_GLabels, S_GSDD, S_GLambda, S_GTransmission, S_Whole, S_GTrans_err
248       
249End
250
251//reads the file and assigns header information to the proper table
252//
253//fname - is the full path:name of the datafile (used by Open)
254//sname - is the name only, used as the filename field
255//
256// takes care of all necessary open/close of file
257//
258Function GetTransHeaderInfoToWave(fname,sname)
259        String fname,sname
260       
261        Variable isTrans
262
263        Variable lastPoint
264
265        isTrans = isTransFile(fname)
266        // decalre the correct set of waves
267        // S_Whole is only a place holder so the waves are of equal length
268        if (isTrans)
269                Wave/T GSuffices = $"root:myGlobals:TransHeaderInfo:T_Suffices"
270                Wave/T G_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
271                Wave/T GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
272                Wave/T GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix"
273                Wave/T GLabels = $"root:myGlobals:TransHeaderInfo:T_Labels"
274                Wave GSDD = $"root:myGlobals:TransHeaderInfo:T_SDD"
275                Wave GLambda = $"root:myGlobals:TransHeaderInfo:T_Lambda"
276                Wave GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission"
277                Wave GWhole = $"root:myGlobals:TransHeaderInfo:T_Whole"
278        Else
279                Wave/T GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices"
280                Wave/T G_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
281                Wave/T GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames"
282                Wave/T GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix"
283                Wave/T GLabels = $"root:myGlobals:TransHeaderInfo:S_Labels"
284                Wave GSDD = $"root:myGlobals:TransHeaderInfo:S_SDD"
285                Wave GLambda = $"root:myGlobals:TransHeaderInfo:S_Lambda"
286                Wave GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission"
287                Wave S_GTrans_err =  $"root:myGlobals:TransHeaderInfo:S_Trans_Error"
288                Wave GWhole = $"root:myGlobals:TransHeaderInfo:S_Whole"
289               
290                        //Transmission error
291                        InsertPoints lastPoint,1,S_GTrans_err
292                        S_GTrans_err[lastPoint] = getSampleTransError(fname)
293                       
294        Endif
295
296        lastPoint = numpnts(GLambda)
297       
298        InsertPoints lastPoint,1,G_TRANS_Filenames
299        G_TRANS_Filenames[lastPoint]=""
300
301        InsertPoints lastPoint,1,GFilenames
302        GFilenames[lastPoint]=sname
303       
304        //read the file suffix
305        InsertPoints lastPoint,1,GSuffix
306        GSuffix[lastPoint]=getSuffix(fname)
307
308        //read any suffix that this file is associated with
309        InsertPoints lastPoint,1,GSuffices
310        GSuffices[lastPoint]=getAssociatedFileSuffix(fname)
311           
312        // read the sample.label text field
313        InsertPoints lastPoint,1,GLabels
314        GLabels[lastPoint]=getSampleLabel(fname)
315           
316
317        //Transmission
318        InsertPoints lastPoint,1,GTransmission
319        GTransmission[lastPoint]=getSampleTrans(fname)
320       
321
322       
323        //Whole detector Transmission
324        InsertPoints lastPoint,1,GWhole
325        GWhole[lastPoint]=getSampleTransWholeDetector(fname)
326           
327        //SDD
328        InsertPoints lastPoint,1,GSDD
329        GSDD[lastPoint]=getSDD(fname)
330           
331        //wavelength
332        InsertPoints lastPoint,1,GLambda
333        GLambda[lastPoint]=getWavelength(fname)
334       
335        return(0)
336End
337
338//fills in the file relations that have already been set
339//
340//
341Function GetFilenamesFromSuffices()
342        Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
343        Wave/T T_GSuffices = $"root:myGlobals:TransHeaderInfo:T_Suffices"
344        Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
345        Wave/T T_GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix"
346       
347        Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
348        Wave/T S_GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices"
349        Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames"
350        Wave/T S_GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix"
351       
352        Variable num_s_files, num_t_files, ii, jj
353        num_t_files = numpnts(T_GFilenames)
354        num_s_files = numpnts(S_GFilenames)
355        //print num_t_files, num_s_files
356       
357        // Get transmission file relations
358        ii= 0
359        do
360                if (cmpstr(T_GSuffices[ii],"")!=0)
361                        jj=0
362                        do
363                                if (cmpstr(T_GSuffices[ii],T_GSuffix[jj])==0)
364                                        T_EMP_Filenames[ii]=T_GFilenames[jj]
365                                endif
366                        jj+=1
367                        while(jj<num_t_files)
368                endif
369                ii+=1
370        while(ii<num_t_files)
371 
372        // Get scattering file relations
373        ii= 0
374        do
375                if (cmpstr(S_GSuffices[ii],"")!=0)
376                        jj=0
377                        do
378                                if (cmpstr(S_GSuffices[ii],T_GSuffix[jj])==0)
379                                        S_TRANS_Filenames[ii]=T_GFilenames[jj]
380                                endif
381                        jj+=1
382                        while(jj<num_t_files)
383                endif
384                ii+=1
385        while(ii<num_s_files)
386End
387
388// gets the selected transmission filename, and puts its name as the
389//empty beam reference file
390// lists the xy box coordinates as read from the file header (zeros if not yet assigned)
391//
392Function PickEMPTransButton(ctrlName) : ButtonControl
393        String ctrlName
394       
395        Variable TransFileTableExists
396        TransFileTableExists = WinType("TransFileTable")
397        //??BUG?? V_flag returns 1 even if no selection?
398        //check manually for null selection
399        //Print "local v_flag = ",num2str(V_flag)
400        Wave/T LocFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
401        if (TransFileTableExists != 0)
402                String/G root:myGlobals:TransHeaderInfo:gEMP = ""
403                GetSelection table,TransFileTable,7
404                //Print S_Selection
405                if(strsearch(S_selection,"T_Filenames",0) == 0)
406                   //selection OK, add to list
407                        Duplicate/O/R=[V_startRow,V_endRow] LocFilenames, filenames
408                        Wave/T selectedFiles = $"filenames"
409
410                        SVAR temp = root:myGlobals:TransHeaderInfo:gEMP
411                        //
412                        temp = temp+selectedFiles[0]            //take just the first file
413                       
414                        UpdateBoxCoordinates()
415                       
416                        //check to make sure that if the box is set, that the count value in the box is set too...
417                        // if the box is set by a protocol, then the counts are not set -> and the transmission will be INF
418                        String tempName = FindValidFilename(temp)
419                        if(cmpstr(tempName,"")==0)
420                                //file not found, get out
421                                Abort "Empty beam file not found UpdateBoxCoordinates(ctrlName)"
422                        Endif
423                        //name is ok, prepend path to tempName for read routine
424                        PathInfo catPathName
425                        String filename = S_path + tempName
426                        Variable boxCounts = getBoxCounts(filename)
427                       
428                        variable x1,x2,y1,y2
429                        getXYBoxFromFile(filename,x1,x2,y1,y2)
430                       
431                        if( (boxCounts == 0) && (x1!=0) && (x2!=0) && (y1!=0) && (y2!=0) )
432                                DoAlert 0,"Box Counts were not recorded. Please re-select the box using SetXYBox"
433                        endif
434                       
435                       
436                Else
437                        DoWindow/F TransFileTable
438                        DoAlert 0,"Invalid selection from the Transmision file table. You must select a file from the T_Filenames column"
439                Endif
440        else
441                //no selection
442                DoAlert 0,"No file selected from Transmission file table or no Transmission file table available"
443        Endif
444End
445
446//initialize data folder and globals for the Trans panel as needed
447//since this operation is somewhat tangled with the Patch Panel, keep all of the
448//globals in the Patch subfolder (make sure both panels are simultaneously initialized)
449//do not create a separate Trans folder
450//
451Proc InitializeTransPanel()
452        //create the global variables needed to run the Trans Panel
453        //all are kept in root:myGlobals:TransHeaderInfo
454        If( ! (DataFolderExists("root:myGlobals:TransHeaderInfo"))  )
455                //create the data folder and the clobals for BOTH the Patch and Trans Panels
456                NewDataFolder/O root:myGlobals:TransHeaderInfo
457                CreateTransGlobals()
458        Endif
459End
460
461
462//
463Proc CreateTransGlobals()
464
465        PathInfo catPathName
466        If(V_flag==1)
467                String dum = S_path
468                String/G root:myGlobals:TransHeaderInfo:gCatPathStr = dum
469        else
470                String/G root:myGlobals:TransHeaderInfo:gCatPathStr = "no path selected"
471        endif
472
473        String/G root:myGlobals:TransHeaderInfo:gEMP = "no file selected"
474        String/G root:myGlobals:TransHeaderInfo:gBox = ""
475        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Suffices"
476        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
477        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Filenames"
478        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Suffix"
479        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Labels"
480        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_SDD"
481        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Lambda"
482        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Transmission"
483        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Whole"
484       
485        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Suffices"
486        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
487        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Filenames"
488        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Suffix"
489        Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Labels"
490        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_SDD"
491        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Lambda"
492        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Transmission"
493        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Trans_Error"
494        Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Whole"
495End
496
497
498//function that writes out (to the header of a raw binary SANS file)
499//characters representing the empty beam file and the sample transmission file
500//the 4-character file suffix is written, rather than the run numbers
501//from this, the trans files can be located, and the
502//sample file contains all the information needed to calculate its transmission
503//
504//uses first 4 bytes of params.reserve (character field) starting at byte 404
505//(previous version (AM) used run.reserve field @ byte 91, which was not empty, and not at the start of the field!)
506//
507Function AssignSelTransFilesToData(startRow,endRow)
508        Variable startRow,endRow
509
510//      GetSelection table,ScatterFileTable,1
511       
512        Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
513        Wave/T T_GSuffices = $"root:myGlobals:TransHeaderInfo:T_Suffices"
514        Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
515        Wave/T T_GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix"
516       
517        Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
518        Wave/T S_GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices"
519        Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames"
520        Wave/T S_GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix"
521       
522        Variable num_s_files, num_t_files, ii, jj
523        Variable refnum
524        num_t_files = numpnts(T_GFilenames)
525        String suffix = ""
526        PathInfo catPathName
527        String pathname = S_path
528        String filename
529
530        // Write suffix of empty beam file into transmission files
531        ii= 0
532        do
533                if (cmpstr(T_EMP_Filenames[ii],"")!=0)
534                        jj=0
535                        do
536                                if (cmpstr(T_EMP_Filenames[ii],T_GFilenames[jj])==0)
537                                        suffix=T_GSuffix[jj]
538                                        filename = pathname + T_GFilenames[ii]
539                                        WriteAssocFileSuffixToHeader(filename,suffix)
540                                endif
541                                jj+=1
542                        while(jj<num_t_files)
543                endif
544        ii+=1
545        while(ii<num_t_files)
546 
547        // Write suffix of transmission files into scattering files
548        ii= startRow
549        do
550                if (cmpstr(S_TRANS_Filenames[ii],"")!=0)
551                        jj=0
552                        do
553                                if (cmpstr(S_TRANS_Filenames[ii],T_GFilenames[jj])==0)
554                                        suffix=T_GSuffix[jj]
555                                        filename = pathname + S_GFilenames[ii]
556                                        WriteAssocFileSuffixToHeader(filename,suffix)
557                                endif
558                                jj+=1
559                        while(jj<num_t_files)
560                endif
561                ii+=1
562        while(ii<=endRow)
563        return(0)
564End
565
566// Allows to calculate transmissions without need of a scattering file. Used with the Calculate Total Trans button.
567
568Function AssignTotalTransFilesToData(startRow,endRow)
569        Variable startRow,endRow
570
571//      GetSelection table,ScatterFileTable,1
572       
573        Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
574        Wave/T T_GSuffices = $"root:myGlobals:TransHeaderInfo:T_Suffices"
575        Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
576        Wave/T T_GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix"
577
578        Variable num_t_files, ii, jj
579        Variable refnum
580        num_t_files = numpnts(T_GFilenames)
581        String suffix = ""
582        PathInfo catPathName
583        String pathname = S_path
584        String filename
585
586        // Write suffix of empty beam file into transmission files
587        ii= 0
588        do
589                if (cmpstr(T_EMP_Filenames[ii],"")!=0)
590                        jj=0
591                        do
592                                if (cmpstr(T_EMP_Filenames[ii],T_GFilenames[jj])==0)
593                                        suffix=T_GSuffix[jj]
594                                        filename = pathname + T_GFilenames[ii]
595                                        WriteAssocFileSuffixToHeader(filename,suffix)
596                                endif
597                                jj+=1
598                        while(jj<num_t_files)
599                endif
600        ii+=1
601        while(ii<num_t_files)
602 
603        return(0)
604End
605
606
607//function that clears the selected assignments of sample trans -> sample scattering
608//also writes a trans=1 value back to the sample file
609//
610// DEC 2006 - now also writes blank suffix to clear trans->empty assignment, and Twhole=1
611//
612// target = 1 = ScatterFileTable
613// target = 2 = TransFileTable
614Function fClearSelectedAssignments(startRow,endRow,target)
615        Variable startRow,endRow,target
616       
617        Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
618        Wave/T S_GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices"
619        Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames"
620        Wave/T S_GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix"
621        Wave S_GTransmission =  $"root:myGlobals:TransHeaderInfo:S_Transmission"
622        Wave S_GTrans_err =  $"root:myGlobals:TransHeaderInfo:S_Trans_Error"
623        Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
624        Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
625        Wave/T T_GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix"
626        Wave T_GTransmission =  $"root:myGlobals:TransHeaderInfo:T_Transmission"
627        Wave T_GTWhole =  $"root:myGlobals:TransHeaderInfo:T_Whole"
628       
629       
630        Variable num_s_files, num_t_files, ii, jj
631        Variable refnum,zero=0
632        num_t_files = numpnts(T_GFilenames)
633        String suffix = "    "          //4 blank spaces
634        PathInfo catPathName
635        String pathname = S_path
636        String filename
637
638// If the selection is from the TransFileTable
639// - wipe out the box coordinates
640// - wipe out the suffix
641// - wipe out the transmission
642// - wipe out T_whole
643// - update the waves in the table
644
645        if(target == 2)
646                ii= startRow
647                do
648                        filename = pathname + T_GFilenames[ii]
649                       
650                        // write in zeros for the box coordinates
651                        WriteXYBoxToHeader(filename,0,0,0,0)
652                       
653                        // write in a null suffix
654                        WriteAssocFileSuffixToHeader(filename,suffix)
655                       
656                        //write a trans==1 to the file header of the raw data
657                        WriteTransmissionToHeader(filename,1)           //sample trans
658                       
659                        WriteWholeTransToHeader(filename,1)             //WholeTrans start byte is 392
660                       
661                        WriteTransmissionErrorToHeader(filename,0)                      //reset transmission error to zero
662                        WriteBoxCountsErrorToHeader(filename,0)
663                       
664                        //then update the table that is displayed
665                        T_EMP_Filenames[ii] = ""
666                        T_GTransmission[ii] = 1
667                        T_GTWhole[ii] = 1
668                       
669                        ii+=1
670                while(ii<=endRow)
671        endif
672       
673 
674        if(target == 1)
675                // Write null suffix of transmission files into scattering files
676                ii= startRow
677                do
678                        filename = pathname + S_GFilenames[ii]
679                        // write in a null suffix
680                        WriteAssocFileSuffixToHeader(filename,suffix)
681                       
682                        //write a trans==1 to the file header of the raw data (open/close done in function)
683                        WriteTransmissionToHeader(filename,1)           //sample trans
684                        WriteTransmissionErrorToHeader(filename,0)                      //reset transmission error to zero
685                        WriteBoxCountsErrorToHeader(filename,0)
686                       
687                        //then update the table that is displayed
688                        S_TRANS_Filenames[ii] = ""
689                        S_GTransmission[ii] = 1
690                        S_GTrans_err[ii] = 0
691                       
692                        ii+=1
693                while(ii<=endRow)
694        endif
695       
696        return(0)
697End
698
699//given a selection of scattering files, calculates the transmission
700//and writes the new transmission to the file header
701//
702//given the full path;name;vers  (= filenmame), of a raw binary SANS file,
703//the transmission of the sample is calculated (if possible) from information
704//in the file header. empty beam and sample transmision run numbers are extracted
705//and the files are located from the run number (if possible)
706//from the header of the empty beam file, the XY box coordinates and "empty"
707//counts are determined
708//once all information is located, the transmission is calculated and the
709//transmission field of the sample file is automatically "Patched"
710// - updates the global variable that is displayed in the panel
711//can be run in batch mode, sequentially passing each item from a list of filenames
712//this is the single step of the batch mode
713//
714//in batch mode: execution will proceed through all of the files, reporting
715//results to the history window. If no trans could be successfully calculated
716//(for a blocked beam, for example), then that is displayed as well, and the
717//raw data is not modified
718//
719// now takes the attenuation of the sample trans and empty beam trans into account, (normally this == 1)
720// and rescales the transmission as appropriate
721// 3/31/04  SRK
722//
723Function CalcSelTransFromHeader(startRow,endRow)
724        Variable startRow,endRow
725//      GetSelection table,ScatterFileTable,1
726
727        String filename
728        Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
729        Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
730       
731        Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
732        Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames"
733        Wave S_GTransmission =  $"root:myGlobals:TransHeaderInfo:S_Transmission"
734        Wave S_GTrans_err =  $"root:myGlobals:TransHeaderInfo:S_Trans_Error"
735
736        Variable num_s_files, num_t_files, ii, jj
737        Variable refnum, transCts, emptyCts,attenRatio,lambda,trans,sam_atten_err,emp_atten_err
738        Variable x1,x2,y1,y2,err,attenEmp,attenSam,empty_ct_err,sam_ct_err,samAttenFactor,empAttenFactor,trans_err
739        String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr
740        String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
741        String strToExecute
742       
743        num_t_files = numpnts(T_GFilenames)
744       
745        PathInfo catPathName
746        pathname = S_path
747
748        ii= startRow
749        do
750                if (cmpstr(S_TRANS_Filenames[ii],"")!=0)        //if there is a sample trans file assigned
751                        jj=0
752                        do
753                                if (cmpstr(S_TRANS_Filenames[ii],T_GFilenames[jj])==0)  //find it in the trans file table
754                                        if (cmpstr(T_EMP_Filenames[jj],"")!=0)          //if empty beam file assigned, proceed with the calculation
755                                                //full path+name to access all 3 files
756                                                filename=pathname+S_GFilenames[ii]
757                                                emptyFile = pathname+T_EMP_Filenames[jj]
758                                                transFile = pathname+T_GFilenames[jj]
759                                                //////////
760                                                // check the empty beam file for previously selected coordinates
761                                                //if they exist, set the xy string , save the normalized counts somewhere
762                                                //the value was written to an unused r*4 header analysis.factor (@b494)
763                                                GetXYBoxFromFile(emptyFile,x1,x2,y1,y2)
764                                               
765                                                //read the real count value
766                                                emptyCts = getBoxCounts(emptyFile)
767                                                // get the error in count value
768                                                empty_ct_err = getBoxCountsError(emptyFile)
769                                               
770                                                // read the attenuator number of the empty beam file
771                                                attenEmp = getAttenNumber(emptyFile)
772                                                //
773                                                if( ((x1-x2)==0) || ((y1-y2)==0) )              //zero width marquee in either direction
774                                                        //no region selected    -- prompt user to select box w/marquee
775                                                        DoWindow/F TransFileTable
776                                                        Abort "Use \"Set BCENT File\", then \"SetXYBox\" to select XY range in empty beam file "+T_EMP_Filenames[jj]
777                                                        //from here the Marquee menu selection must handle the task of setting the box and updating the information in the file header
778                                                Endif
779               
780                                                //read in trans file then add to SAM
781                                                ReadHeaderAndData(transFile)
782                                                //adds to SAM
783                                                err = Raw_to_work("SAM")
784                                                //sum region in SAM
785                                                transCts =  SumCountsInBox(x1,x2,y1,y2,sam_ct_err,"SAM")       
786                                                // get the attenuator, lambda, and sample string (to get the instrument)
787                                                WAVE/T samText = $"root:Packages:NIST:SAM:textRead"
788                                                WAVE samReals = $"root:Packages:NIST:SAM:realsRead"
789                                                samfileStr = samText[3]
790                                                lambda = samReals[26]
791                                                attenSam = samReals[3]
792                                               
793                                                //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda
794                                                samAttenFactor = AttenuationFactor(samFileStr,lambda,attenSam,sam_atten_err)
795                                                empAttenFactor = AttenuationFactor(samFileStr,lambda,attenEmp,emp_atten_err)
796                                                AttenRatio = empAttenFactor/samAttenFactor
797                                                //calculate trans based on empty beam value and rescale by attenuation ratio
798                                                trans= transCts/emptyCts * AttenRatio
799                                               
800                                                // squared, relative error
801                                                if(AttenRatio == 1)
802                                                        trans_err = (sam_ct_err/transCts)^2 + (empty_ct_err/emptyCts)^2         //same atten, att_err drops out
803                                                else
804                                                        trans_err = (sam_ct_err/transCts)^2 + (empty_ct_err/emptyCts)^2 + (sam_atten_err/samAttenFactor)^2 + (emp_atten_err/empAttenFactor)^2
805                                                endif
806                                                trans_err = sqrt(trans_err)
807                                                trans_err *= trans              // now, one std deviation
808                                               
809                                                //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity
810                                                If(attenRatio==1)
811                                                        Printf "%s\t\tTrans Counts = %g\tTrans = %g +/- %g\r",S_GFilenames[ii], transCts,trans,trans_err
812                                                else
813                                                        Printf "%s\t\tTrans Counts = %g\tTrans = %g +/- %g\tAttenuatorRatio = %g\r",S_GFilenames[ii], transCts,trans,trans_err,attenRatio
814                                                endif
815                                                //write the trans to the file header of the raw data (open/close done in function)
816                                                WriteTransmissionToHeader(filename,trans)
817                                               
818                                                WriteTransmissionErrorToHeader(filename,trans_err)
819/////                                           
820                                                //then update the global that is displayed
821                                                S_GTransmission[ii] = trans
822                                                S_GTrans_err[ii] = trans_err
823
824                                               
825                                        else  // There is no empty assigned
826                                                abortStr = "Empty beam file not assigned properly for " + T_GFilenames[jj]
827                                                Print abortStr
828                                                //Abort abortStr
829                                                return(1)
830                                        endif
831                                endif
832                                jj+=1
833                        while(jj<num_t_files)
834                else //no transmission file
835                        abortStr = "Transmission beam file not assigned properly for " + S_GFilenames[ii]
836                        Print abortStr
837                endif
838                ii+=1
839        while(ii<=endRow)
840        print "done"
841        return(0)
842End
843
844//
845// For the calculation of the Transmission using only the Trans Files screen
846// Uses only the information on the transmissionFiles screen to calculate
847// a "box" Transmission for comparison with the Whole Transmission
848// updated 5/11/2006 by Bryan Greenwald
849Function CalcTotalTrans(startRow,endRow)
850        Variable startRow,endRow
851//      GetSelection table,ScatterFileTable,1
852
853        String filename
854        Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
855       
856        Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
857        Wave T_GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission"
858       
859//      Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
860//      Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames"
861//      Wave S_GTransmission =  $"root:myGlobals:TransHeaderInfo:S_Transmission"
862        Wave GWhole= $"root:myGlobals:TransHeaderInfo:T_Whole"
863       
864        Variable num_t_files, ii, jj
865        Variable refnum, transCts, emptyCts,attenRatio,lambda,trans,samAttenFactor,empAttenFactor,trans_err
866        Variable x1,x2,y1,y2,err,attenEmp,attenSam,empty_ct_err,sam_ct_err,emp_atten_err,sam_atten_err
867        String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr
868        String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
869        String strToExecute
870       
871        num_t_files = numpnts(T_GFilenames)
872       
873        PathInfo catPathName
874        pathname = S_path
875
876        ii= startRow
877        do
878                if (cmpstr(T_Emp_Filenames[ii],"")!=0)  //if there is a sample trans file assigned
879                        jj=0
880                        do
881                                if (cmpstr(T_Emp_Filenames[ii],T_GFilenames[jj])==0)    //find it in the trans file table
882                                        if (cmpstr(T_EMP_Filenames[ii],"")!=0)          //if empty beam file assigned, proceed with the calculation
883                                                //full path+name to access all 3 files
884                                                filename=pathname+T_GFilenames[ii]
885                                                emptyFile = pathname+T_EMP_Filenames[ii]
886                                                transFile = pathname+T_GFilenames[ii]
887                                                //////////
888                                                // check the empty beam file for previously selected coordinates
889                                                //if they exist, set the xy string , save the normalized counts somewhere
890                                                //the value was written to an unused r*4 header analysis.factor (@b494)
891                                                getXYBoxFromFile(emptyFile,x1,x2,y1,y2)
892                                               
893                                                //read the real count value
894                                                emptyCts = getBoxCounts(emptyFile)
895                                                // get the count error
896                                                empty_ct_err = getBoxCountsError(emptyFile)
897                                               
898                                                // read the attenuator number of the empty beam file
899                                                attenEmp = getAttenNumber(emptyFile)
900                                               
901                                                //
902                                                if( ((x1-x2)==0) || ((y1-y2)==0) )              //zero width marquee in either direction
903                                                        //no region selected    -- prompt user to select box w/marquee
904                                                        DoWindow/F TransFileTable
905                                                        Abort "Use \"Set BCENT File\", then \"SetXYBox\" to select XY range in empty beam file "+T_EMP_Filenames[jj]
906                                                        //from here the Marquee menu selection must handle the task of setting the box and updating the information in the file header
907                                                Endif
908               
909                                                //read in trans file then add to SAM
910                                                ReadHeaderAndData(transFile)
911                                                //adds to SAM
912                                                err = Raw_to_work("SAM")
913                                                //sum region in SAM
914                                                transCts =  SumCountsInBox(x1,x2,y1,y2,sam_ct_err,"SAM")       
915                                                // get the attenuator, lambda, and sample string (to get the instrument)
916                                                WAVE/T samText = $"root:Packages:NIST:SAM:textRead"
917                                                WAVE samReals = $"root:Packages:NIST:SAM:realsRead"
918                                                samfileStr = samText[3]
919                                                lambda = samReals[26]
920                                                attenSam = samReals[3]
921                                               
922                                                //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda
923                                                samAttenFactor = AttenuationFactor(samFileStr,lambda,attenSam,sam_atten_err)
924                                                empAttenFactor = AttenuationFactor(samFileStr,lambda,attenEmp,emp_atten_err)
925                                                AttenRatio = empAttenFactor/samAttenFactor
926                                                //calculate trans based on empty beam value and rescale by attenuation ratio
927                                                trans= transCts/emptyCts * AttenRatio
928                                               
929                                                // squared, relative error
930                                                if(AttenRatio == 1)
931                                                        trans_err = (sam_ct_err/transCts)^2 + (empty_ct_err/emptyCts)^2         //same atten, att_err drops out
932                                                else
933                                                        trans_err = (sam_ct_err/transCts)^2 + (empty_ct_err/emptyCts)^2 + (sam_atten_err/samAttenFactor)^2 + (emp_atten_err/empAttenFactor)^2
934                                                endif
935                                                trans_err = sqrt(trans_err)
936                                                trans_err *= trans              // now, one std deviation                                               
937                                               
938                                                //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity
939                                                If(attenRatio==1)
940                                                        //Printf "%s\t\tTrans Counts = %g\t Actual Trans = %g\r",T_GFilenames[ii], transCts,trans
941                                                        Printf "%s\t\tBox Counts = %g\t Trans = %g +/- %g\r",T_GFilenames[ii], transCts,trans,trans_err
942                                                else
943                                                        //Printf "%s\t\tTrans Counts = %g\t Trans = %g\tAttenuatorRatio = %g\r",T_GFilenames[ii], transCts,trans,attenRatio
944                                                        Printf "%s\t\tBox Counts = %g\t Trans = %g +/- %g\t AttenuatorRatio = %g\r",T_GFilenames[ii], transCts,trans,trans_err,attenRatio
945                                                endif
946                                                //write the trans to the file header of the raw data (open/close done in function)
947                                                WriteTransmissionToHeader(filename,trans)               //transmission start byte is 158
948                                               
949                                                WriteTransmissionErrorToHeader(filename,trans_err)
950                                                                                               
951                                                //then update the global that is displayed
952                                                T_GTransmission[ii] = trans
953                                               
954                                        else  // There is no empty assigned
955                                                abortStr = "Empty beam file not assigned properly for " + T_GFilenames[jj]
956                                                Print abortStr
957                                                //Abort abortStr
958                                                return(1)
959                                        endif
960                                endif
961                                jj+=1
962                        while(jj<num_t_files)
963                else //no transmission file
964                        abortStr = "Transmission beam file not assigned properly for " + T_GFilenames[ii]
965                        Print abortStr
966                endif
967                ii+=1
968        while(ii<=endRow)
969        //print "done"
970        return(0)
971End
972
973//
974// For the calculation of the Transmission using only the whole detector
975// Used to compute the transmission for the TransmissionFiles table using
976// the entire detector. For comparison with the "box" trans
977// updated: 5/11/2006 by Bryan Greenwald
978Function CalcWholeTrans(startRow,endRow)
979        Variable startRow,endRow
980//      GetSelection table,ScatterFileTable,1
981
982        NVAR pixelsX = root:myGlobals:gNPixelsX
983        NVAR pixelsY = root:myGlobals:gNPixelsY
984       
985        String filename
986        Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames"
987       
988        Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames"
989        Wave T_GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission"
990       
991//      Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames"
992//      Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames"
993//      Wave S_GTransmission =  $"root:myGlobals:TransHeaderInfo:S_Transmission"
994        Wave GWhole= $"root:myGlobals:TransHeaderInfo:T_Whole"
995       
996        Variable num_t_files, ii, jj
997        Variable refnum, transCts, emptyCts,attenRatio,lambda,trans
998        Variable x1,x2,y1,y2,err,attenEmp,attenSam,empty_ct_err,sam_ct_err,emp_atten_err,sam_atten_err
999        String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr
1000        String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q"
1001        String strToExecute
1002       
1003        num_t_files = numpnts(T_GFilenames)
1004       
1005        PathInfo catPathName
1006        pathname = S_path
1007
1008        ii= startRow
1009        do
1010                if (cmpstr(T_Emp_Filenames[ii],"")!=0)  //if there is a sample trans file assigned
1011                        jj=0
1012                        do
1013                                if (cmpstr(T_Emp_Filenames[ii],T_GFilenames[jj])==0)    //find it in the trans file table
1014                                        if (cmpstr(T_EMP_Filenames[ii],"")!=0)          //if empty beam file assigned, proceed with the calculation
1015                                                //full path+name to access all 3 files
1016                                                filename=pathname+T_GFilenames[ii]
1017                                                emptyFile = pathname+T_EMP_Filenames[ii]
1018                                                transFile = pathname+T_GFilenames[ii]
1019                                                //////////
1020                                                // check the empty beam file for previously selected coordinates
1021                                                //if they exist, set the xy string , save the normalized counts somewhere
1022                                                //the value was written to an unused r*4 header analysis.factor (@b494)
1023                                               
1024                                                getXYBoxFromFile(emptyFile,x1,x2,y1,y2)
1025                                                //read the real count value
1026                                                emptyCts = getBoxCounts(emptyFile)
1027                                                // get the box count error
1028                                                empty_ct_err = getBoxCountsError(emptyFile)
1029                                               
1030                                                // read the attenuator number of the empty beam file
1031                                                attenEmp = getAttenNumber(emptyFile)
1032                                               
1033                                                //
1034                                                if( ((x1-x2)==0) || ((y1-y2)==0) )              //zero width marquee in either direction
1035                                                        //no region selected    -- prompt user to select box w/marquee
1036                                                        DoWindow/F TransFileTable
1037                                                        Abort "Use \"Set BCENT File\", then \"SetXYBox\" to select XY range in empty beam file "+T_EMP_Filenames[jj]
1038                                                        //from here the Marquee menu selection must handle the task of setting the box and updating the information in the file header
1039                                                Endif
1040               
1041                                                //read in trans file then add to SAM
1042                                                ReadHeaderAndData(transFile)
1043                                                //adds to SAM
1044                                                err = Raw_to_work("SAM")
1045                                                //sum region in SAM
1046                                                transCts =  SumCountsInBox(0,pixelsX-1,0,pixelsY-1,sam_ct_err,"SAM")   
1047                                                // get the attenuator, lambda, and sample string (to get the instrument)
1048                                                WAVE/T samText = $"root:Packages:NIST:SAM:textRead"
1049                                                WAVE samReals = $"root:Packages:NIST:SAM:realsRead"
1050                                                samfileStr = samText[3]
1051                                                lambda = samReals[26]
1052                                                attenSam = samReals[3]
1053                                               
1054                                                //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda
1055                                                AttenRatio = AttenuationFactor(samFileStr,lambda,attenEmp,emp_atten_err)/AttenuationFactor(samFileStr,lambda,attenSam,sam_atten_err)
1056                                                //calculate trans based on empty beam value and rescale by attenuation ratio
1057                                                trans= transCts/emptyCts * AttenRatio
1058                                               
1059                                                //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity
1060                                                If(attenRatio==1)
1061                                                        //Printf "%s\t\tTrans Counts = %g\tTrans using whole detector = %g\t Tbox/Twhole = %g\r",T_GFilenames[ii], transCts,trans,T_GTransmission[ii]/trans
1062                                                        Printf "%s\t\tTotal Counts = %g\t Trans using whole detector = %g\t",T_GFilenames[ii], transCts,trans
1063                                                else
1064                                                        //Printf "%s\t\tTrans Counts = %g\tTrans = %g\tAttenuatorRatio = %g, Tbox/Twhole = %g\r",T_GFilenames[ii], transCts,trans,attenRatio, T_GTransmission[ii]/trans
1065                                                        Printf "%s\t\tTotal Counts = %g\t Trans using whole detector = %g\t AttenuatorRatio = %g",T_GFilenames[ii], transCts,trans,attenRatio
1066                                                endif
1067                                                If(T_GTransmission[ii]/trans > 0.95)            //95%, from conversation w/Lionel
1068                                                        printf " Tbox/Twhole = %g\r",T_GTransmission[ii]/trans
1069                                                else
1070                                                        printf " !!! Tbox/Twhole is low !!! = %g\r",T_GTransmission[ii]/trans
1071                                                endif
1072                                                //write the trans to the file header of the raw data (open/close done in function)
1073                                                WriteWholeTransToHeader(filename,trans)
1074                                               
1075                                                //then update the global that is displayed
1076                                                GWhole[ii] = trans
1077                                               
1078                                        else  // There is no empty assigned
1079                                                abortStr = "Empty beam file not assigned properly for " + T_GFilenames[jj]
1080                                                Print abortStr
1081                                                //Abort abortStr
1082                                                return(1)
1083                                        endif
1084                                endif
1085                                jj+=1
1086                        while(jj<num_t_files)
1087                else //no transmission file
1088                        abortStr = "Transmission beam file not assigned properly for " + T_GFilenames[ii]
1089                        Print abortStr
1090                endif
1091                ii+=1
1092        while(ii<=endRow)
1093        print "done"
1094        return(0)
1095End
1096
1097
1098//window recreation macro for the Trans Panel
1099//
1100Proc Trans_Panel()
1101        PauseUpdate; Silent 1           // building window...
1102        NewPanel /W=(173,197,548,444) /K=1 as "Calculate Transmissions"
1103        DoWindow/C Trans_Panel
1104        ModifyPanel cbRGB=(49807,47186,38011)
1105        ModifyPanel fixedSize=1
1106        SetDrawLayer UserBack
1107        DrawLine 0,56,368,56
1108        DrawLine 0,142,368,142
1109        Button pick_emp,pos={4,65},size={105,20},proc=PickEMPTransButton,title="set EMPTY file"
1110        Button pick_emp,help={"This button will set the file selected in the Transmission file table to be the empty beam file."}
1111        SetVariable empStr,pos={114,67},size={250,17},title="file:"
1112        SetVariable empStr,help={"Filename of the empty beam file(s) to be used in the transmission calculation"}
1113        SetVariable empStr,fSize=10
1114        SetVariable empStr,limits={-Inf,Inf,0},value= root:myGlobals:TransHeaderInfo:gEMP
1115        Button Trn_button_1,pos={5,91},size={90,20},proc=Trn_SetXYBoxButton,title="Set XY Box"
1116        Button Trn_button_1,help={"Sets the XY box to sum over"}
1117        Button Trn_button_2,pos={174,156},size={110,20},proc=Trn_SortFilesByDate,title="Sort by Date"
1118        Button Trn_button_2,help={"Sort the scattering and transmission files by creation date."}
1119        Button Trn_button_3,pos={174,186},size={110,20},proc=Trn_SortFilesByLabel,title="Sort by Label"
1120        Button Trn_button_3,help={"Sort the scattering and transmission files by label."}
1121        SetVariable Trn_setvar_1,pos={135,90},size={227,17},title="Box is "
1122        SetVariable Trn_setvar_1,help={"Box coordinates to sum over"},fSize=10
1123        SetVariable Trn_setvar_1,limits={-Inf,Inf,0},value= root:myGlobals:TransHeaderInfo:gBox
1124        Button Trn_button_0,pos={1,1},size={70,20},proc=Trn_PickPathButton,title="Pick Path"
1125        Button Trn_button_0,help={"Select the folder containing the SANS data files"}
1126        Button Trn_button_9,pos={335,1},size={25,20},proc=ShowTransHelp,title="?"
1127        Button Trn_button_9,help={"Show the help file for calculating sample transmissions"}
1128        SetVariable Trn_setvar_0,pos={80,4},size={250,17},title="Path"
1129        SetVariable Trn_setvar_0,help={"Currently selected data path"},fSize=10
1130        SetVariable Trn_setvar_0,limits={-Inf,Inf,0},value= root:myGlobals:TransHeaderInfo:gCatPathStr
1131        Button Trn_button_5,pos={5,186},size={161,20},proc=Trn_CalcAllFilesButton,title="Calculate All Files"
1132        Button Trn_button_5,help={"Calculate transmission and patch headers of ALL files in the Scattering File Table."}
1133        Button Trn_button_6,pos={295,215},size={67,20},proc=Trn_PanelDoneButtonProc,title="Done"
1134        Button Trn_button_6,help={"Close the panel when done calculating transmissions"}
1135        Button Trn_button_7,pos={67,32},size={214,20},proc=Trn_RefreshProc,title="List Files"
1136        Button Trn_button_7,help={"Generate or refresh the tables of files."}
1137        Button Trn_button_8,pos={5,156},size={161,20},proc=Trn_CalcSelectedFilesButton,title="Calculate Selected Files"
1138        Button Trn_button_8,help={"Calculate transmission and patch headers of selected files in the Scattering File Table."}
1139        Button Trn_button_10,pos={5,215}, size={161,20},proc=TotalTransButtonProc
1140        Button Trn_button_10 title="Calculate Total Trans"
1141        Button Trn_button_10 help={"Calculate transmission over the whole detector and patch headers of ALL files in the data folder."}
1142        Button setEmpForAll,pos={4,117},size={120,20},proc=FillEMPFilenameWSelection,title="Use EMP for ALL"
1143        Button setEmpForAll,help={"This button will set the file selected in the Transmission file table to be the empty beam file."}
1144        Button ClearTrans,pos={175,215},size={110,20},proc=ClearSelectedAssignments,title="Clear Selection"
1145        Button ClearTrans,help={"This button will set the file selected in the Transmission file table to be the empty beam file."}
1146EndMacro
1147
1148
1149Function TotalTransButtonProc(ctrlName) : ButtonControl
1150        String ctrlName
1151        TotalTrans(ctrlName)
1152End
1153
1154
1155Proc ShowTransHelp(ctrlName) : ButtonControl
1156        String ctrlName
1157        DisplayHelpTopic/Z/K=1 "SANS Data Reduction Tutorial[Calculate Transmissions]"
1158        if(V_flag !=0)
1159                DoAlert 0,"The SANS Data Reduction Tutorial Help file could not be found"
1160        endif
1161End
1162
1163
1164//generates the file tables of scattering files and transmission files
1165//
1166// if the tables already exist, they will be updated
1167//
1168Proc Trn_RefreshProc(ctrlName) : ButtonControl
1169        String ctrlName
1170        BuildFileTables()
1171End
1172
1173//shows a noteboox of help text describing how to calculate transmissions
1174// - better that the user read the igor or pdf file, but it's a victory to get
1175//users to read anything at all
1176//
1177Proc Trn_ShowHelpProc(ctrlName) : ButtonControl
1178        String ctrlName
1179        DisplayTransHelp()
1180End
1181
1182//sorts the tables by date
1183//
1184Proc Trn_SortFilesByDate(ctrlName) : ButtonControl
1185        String ctrlName
1186        SortTransByDate()
1187End
1188
1189//sorts the tables alphabetically by the sample label field
1190//
1191Proc Trn_SortFilesByLabel(ctrlName) : ButtonControl
1192        String ctrlName
1193        SortTransByLabel()
1194End
1195
1196//button action procedure to select the local path to the
1197//folder containing the RAW SANS data files
1198// - once the data folder is selected, all of the popup file menus are
1199//forced to update with fresh file lists
1200//
1201Function Trn_PickPathButton(PathButton) : ButtonControl
1202        String PathButton
1203       
1204        //set the global string to the selected pathname
1205        Variable err
1206        err = PickPath()
1207        if(err)
1208                return(1)               //some problem with path or user cancelled, get out
1209        endif
1210       
1211        PathInfo/S catPathName
1212        String path = S_path
1213        if (V_flag == 0)
1214                //path does not exist - no folder selected
1215                String/G root:myGlobals:TransHeaderInfo:gCatPathStr = "no folder selected"
1216        else
1217                String/G root:myGlobals:TransHeaderInfo:gCatPathStr = path
1218        endif
1219       
1220        //Update the pathStr variable box
1221        ControlUpdate/W=Trans_Panel $"Trn_setvar_0"
1222        //Generate tables
1223        Execute "BuildFileTables()"
1224       
1225End
1226
1227//button action function that asks the user to set the XY box to sum over
1228//for all transmission calculations
1229//
1230// requires the user to set the box coordinates with the marquee popup
1231//that wil properly set the keyword string, and write the values to the empty beam header
1232//
1233Function Trn_SetXYBoxButton(ctrlName) : ButtonControl
1234        String ctrlName
1235
1236        String msgStr = "Select the Empty Beam File"
1237        String filename=""
1238       
1239        //get the filename from the popup menu
1240        //and construct a full path to it
1241        SVAR partialName = root:myGlobals:TransHeaderInfo:gEMP
1242        print partialName
1243        //get a valid file based on this partialName and catPathName
1244        String tempName = FindValidFilename(partialName)
1245        if(cmpstr(tempName,"")==0)
1246                //file not found, get out
1247                Abort "Empty beam file not found Trn_SetXYBoxButton(ctrlName)"
1248        Endif
1249        //name is ok, prepend path to tempName for read routine
1250        PathInfo catPathName
1251        filename = S_path + tempName
1252       
1253        //read the file in - check for previous coordinates
1254        ReadHeaderAndData(filename)
1255        //data is displayed here (go through the normal display steps, so all is created properly
1256        String/G root:myGlobals:gDataDisplayType="RAW"
1257        fRawWindowHook()
1258       
1259        // check the empty beam file for previously selected coordinates
1260        //if they exist, set the xy string , save the normalized counts somewhere
1261        //the value was written to an unused r*4 header analysis.factor (@b494)
1262        Variable refnum,x1,x2,y1,y2,err
1263        getXYBoxFromFile(filename,x1,x2,y1,y2)
1264       
1265        //read the real count value, assign to a global
1266        Variable/G root:myGlobals:gTransCts = getBoxCounts(filename)                    //***NOTE this is NOT in the Trans sub-folder
1267        //
1268        if( ((x1-x2)==0) || ((y1-y2)==0) )              //zero width marquee in either direction
1269                //no region selected
1270               
1271                //add the empty beam file to work.SAM
1272                err = Raw_to_work("SAM")
1273       
1274                //the calling macro must change the display type
1275                String/G root:myGlobals:gDataDisplayType="SAM"          //displayed data type is sam
1276       
1277                //data is displayed here
1278                fRawWindowHook()
1279       
1280                //prompt user to select box w/marquee
1281                DoAlert 0,"Select the region to sum with the Marquee"
1282       
1283                //from here the Marquee menu selection must handle the task of setting the box
1284                //and updating the information in the file header
1285        else
1286                // region already selected, just put up the values from the file header
1287                //allow user the option of overriding the current box region
1288                msgStr = "X1="+num2str(x1)+";"
1289                msgStr += "X2="+num2str(x2)+";"
1290                msgStr += "Y1="+num2str(y1)+";"
1291                msgStr += "Y2="+num2str(y2)+";"
1292                String textStr
1293                textStr = "Override current box  "+msgStr+" ?"
1294                DoAlert 1,textStr
1295                If((V_flag)==1)
1296                        //get new box coordinates, same procedure as above
1297                        //add the empty beam file to work.SAM
1298                        err = Raw_to_work("SAM")
1299       
1300                        //the calling macro must change the display type
1301                        String/G root:myGlobals:gDataDisplayType="SAM"          //displayed data type is sam
1302       
1303                        //data is displayed here
1304                        fRawWindowHook()
1305       
1306                        //prompt user to select box w/marquee
1307                        DoAlert 0,"Select the region to sum with the Marquee"
1308       
1309                        //from here the Marquee menu selection must handle the task of setting the box
1310                        //and updating the information in the file header
1311                else
1312                        String/G root:myGlobals:TransHeaderInfo:gBox = msgStr
1313                Endif
1314        Endif
1315       
1316        UpdateBoxCoordinates()
1317        Return (0)
1318End
1319
1320
1321//button action function that assigns the selected empty beam file (run number only)
1322//and the sample trnansmissionfile (run number only) to the popup list of  sample scattering
1323//files (ALL of the list items). Assignment is done by writing the integer run numbers of
1324//trans files to the header of each of the  scattering files, in a batchwise processing
1325//of the popup list
1326//
1327//transmission are not calculated here - only the file numbers are set
1328//
1329//*********unused***********
1330//Function Trn_AssignAllFilesButton(ctrlName) : ButtonControl
1331//      String ctrlName
1332//
1333//      AssignTransFilesToData()
1334//             
1335//End
1336
1337//button action procedure to calculate the transmission of all of the sample files in the
1338//sample popup list, based on the information in EACH sample header and in the empty beam file
1339//the box must be set properly in the empty beam file, AND the empty and trans
1340//run number must also be set properly in EACH scattering file,
1341//If run numbers are not properly assigned, no trans is calculated and the
1342//header is not modified
1343//
1344//The RAW data header of EACH sample file IS modified, with the newly calculated transmission
1345//
1346//not very friendly, but forces users to assign the files before continuing
1347//
1348Function Trn_CalcAllFilesButton(ctrlName) : ButtonControl
1349        String ctrlName
1350
1351        //calculate the transmission and Patch the header (if possible)
1352        Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames"
1353        Variable num_s_files = numpnts(S_GFilenames)
1354        AssignSelTransFilesToData(0,num_s_files-1)              //do all the files (points 0 to n-1, inclusive)
1355        CalcSelTransFromHeader(0,num_s_files-1)
1356       
1357End
1358
1359//for selected scattering files in the scattering table,
1360// the "Annn" association of trans file is written to the data file,
1361// the the transmission is actually calculated
1362//
1363Function Trn_CalcSelectedFilesButton(ctrlName) : ButtonControl
1364        String ctrlName
1365 
1366   Variable scatterTableExists
1367   scatterTableExists = WinType("ScatterFileTable")
1368   if (scatterTableExists != 0)
1369                GetSelection table,ScatterFileTable,1
1370                if(V_Flag != 0)
1371                        AssignSelTransFilesToData(V_StartRow,V_EndRow)
1372                        //calculate the transmission and Patch the header (if possible)
1373                        CalcSelTransFromHeader(V_StartRow,V_EndRow)
1374                Else
1375                        DoAlert 0,"No selection from Scattering Files table"
1376                Endif
1377   Else
1378                DoAlert 0,"No file selected from Scattering Files table or no Scattering Files table available"
1379   Endif
1380End
1381
1382//
1383// I am not sure what the difference is inthe function of CalcTotalTrans and CalcWholeTrans ?
1384// do they really do anything different?
1385// is it a useful calculation at all?
1386//
1387Function TotalTrans(ctrlName) : ButtonControl
1388        String ctrlName
1389 
1390   Variable transTableExists
1391   transTableExists = WinType("TransFileTable")
1392   if (transTableExists != 0)
1393                GetSelection table,transFileTable,1
1394                if(V_Flag != 0)
1395                        AssignTotalTransFilesToData(V_StartRow,V_EndRow)
1396                        //calculate the transmission and Patch the header (if possible)
1397                        CalcTotalTrans(V_StartRow,V_EndRow)
1398                        CalcWholeTrans(V_StartRow,V_EndRow)
1399                Else
1400                        DoAlert 0,"No selection from Trans Files table"
1401                Endif
1402   Else
1403                DoAlert 0,"No file selected from Trans Files table or no Trans Files table available"
1404   Endif
1405End
1406
1407
1408//simple button procedure to close the trans panel
1409// - automatically kills the two tables as well
1410//
1411Function Trn_PanelDoneButtonProc(ctrlName) : ButtonControl
1412        String ctrlName
1413
1414        // this button will make sure all files are closed
1415        //and close the panel
1416       
1417        Close/A
1418        DoWindow/K Trans_Panel
1419        DoWindow/K ScatterFileTable
1420        DoWindow/K TransFileTable
1421End
1422
1423
1424//function to update the box coordinates of the file selected as the
1425//empty beam file - takes the file that is currently popped from the list
1426//reads the 4 "analysis" integers that hold the box coordinates
1427//resets the globals string that is displayed with the new values
1428//should be called whenever the "empty" popup is popped, to ensure
1429//that current header information is displayed
1430//
1431Function UpdateBoxCoordinates()
1432
1433        //construct a full name, and read in the label from the file
1434        //and set the global
1435        String textstr=""
1436        ControlInfo empStr
1437        SVAR item = root:myGlobals:TransHeaderInfo:gEMP
1438        String tempName = FindValidFilename(item)
1439        if(cmpstr(tempName,"")==0)
1440                //file not found, get out
1441                Abort "Empty beam file not found UpdateBoxCoordinates(ctrlName)"
1442        Endif
1443        //name is ok, prepend path to tempName for read routine
1444        PathInfo catPathName
1445        String filename = S_path + tempName
1446       
1447        Variable refnum,x1,x2,y1,y2,err
1448        GetXYBoxFromFile(filename,x1,x2,y1,y2)
1449       
1450        //and update the global string
1451        String msgStr=""
1452        msgStr = "X1="+num2str(x1)+";"
1453        msgStr += "X2="+num2str(x2)+";"
1454        msgStr += "Y1="+num2str(y1)+";"
1455        msgStr += "Y2="+num2str(y2)+";"
1456       
1457        String/G root:myGlobals:TransHeaderInfo:gBox = msgStr
1458       
1459        ControlUpdate/W=Trans_panel Trn_setvar_1
1460End
1461
1462//crude procedure to display a notebook of help information for users
1463//
1464Proc DisplayTransHelp()
1465        String nb = "Notebook0"
1466        NewNotebook/N=$nb/F=1/V=1/W=(342,302,868,674) as "Notebook0:Transmission Help"
1467        Notebook $nb defaultTab=36, statusWidth=238, pageMargins={36,72,36,72}
1468        Notebook $nb showRuler=1, rulerUnits=1, updating={1, 3600}
1469        Notebook $nb newRuler=Normal, justification=0, margins={0,0,468}, spacing={0,0,0}, tabs={}, rulerDefaults={"Geneva",10,0,(0,0,0)}
1470        Notebook $nb ruler=Normal; Notebook $nb  justification=1, fSize=14, fStyle=1, text="Transmission Help\r"
1471        Notebook $nb ruler=Normal, fSize=-1, fStyle=-1, text="\r"
1472        Notebook $nb text="This panel allows quick and easy calculation of sample transmission. The neutron transmission of a sampl"
1473        Notebook $nb text="e must be calculated and entered into the header of each sample scattering file before proper background"
1474        Notebook $nb text=" corrections or absolute scaling can be done.\r"
1475        Notebook $nb text="\r"
1476        Notebook $nb text="During data collection, you measured an empty beam  - that is a measurement with heavy attenuation of th"
1477        Notebook $nb text="e neutron beam and the beamstop mover out of line with the direct beam. Then without changing the attenu"
1478        Notebook $nb text="ation or replacing the beamstop, you put a sample in the beam, and repeated the measurement (a sample tr"
1479        Notebook $nb text="ansmission measurement). The neutron transmission of the sample is simply the ratio of the number of neu"
1480        Notebook $nb text="tron counts from the sample transmission measurement normalized by the number of neutron counts from the"
1481        Notebook $nb text=" empty beam measurement. In this way, each sample transmission file is \"linked\" to the same empty beam t"
1482        Notebook $nb text="ransmission file.\r"
1483        Notebook $nb text="\r"
1484        Notebook $nb text="This calculated transmission value must be entered into the header of the sample scattering measurement "
1485        Notebook $nb text="- that is the measurement of the sample with the beamstop covering the primary (transmitted) beam, and n"
1486        Notebook $nb text="o (or few) attenuators in place. In this way, the sample transmission file is \"linked\" to its correspond"
1487        Notebook $nb text="ing sample scattering file. This panel allows you to set up the links and calculate the transmission.Tra"
1488        Notebook $nb text="nsmisison values are automatically patched to the scattering file headers as they are calculated.\r"
1489        Notebook $nb text="\r"
1490        Notebook $nb text="To Calculate Transmissions:\r"
1491        Notebook $nb text="\r"
1492        Notebook $nb text="1) Click \"List Files\" to get two lists (tables) - one of all the sample scattering files in the folder, "
1493        Notebook $nb text="and one of the transmission files.\r"
1494        Notebook $nb text="\r"
1495        Notebook $nb text="2) Select the region of the detector to sum over from the empty beam transmission file. Do theis by clic"
1496        Notebook $nb text="king on the filename of the empty beam transmision file (from the TransmissionFiles window, in the blue "
1497        Notebook $nb text="\"T_Filenames\" column). Return to the panel, and click the \"set EMP file\" button\", and the filename shoul"
1498        Notebook $nb text="d appear in the file box. The \"Box is\" field should have zeros for the x and y coordinates. Click the \"S"
1499        Notebook $nb text="et XY Box\" button. The empty beam file will be displayed, and you will be instructed to select the regio"
1500        Notebook $nb text="n to sum with the marquee. On the data, click and drag a rectangle that encompasses the primary beam. Mo"
1501        Notebook $nb text="ve the cursor inside the selection, to get an \"upside-down hat\" cursor. Click to get a menu, and near th"
1502        Notebook $nb text="e bottom, select \"Set XY Box Coords\". The pixel values should be updated to the Transmission panel, and "
1503        Notebook $nb text="are written to the empty beam header for future calculations. Note that the marquee selection can also b"
1504        Notebook $nb text="e used to measure the beam center, or centroid of any selected region.\r"
1505        Notebook $nb text="\r"
1506        Notebook $nb text="3) Now you need to \"link\" the ", fStyle=2, text="sample", fStyle=-1, text=" transmission files to the "
1507        Notebook $nb fStyle=2, text="empty", fStyle=-1, text=" ", fStyle=2, text="beam", fStyle=-1
1508        Notebook $nb text=" transmission file. Do this in the TransmissionFiles window by selecting the filename (in the blue T_Fil"
1509        Notebook $nb text="enames column) and pasing it to the corresponding row(s) in the T_EMP_Filenames column. This links the e"
1510        Notebook $nb text="mpty beam transmission with the sample transmission file. Do this for every sample transmission file.\r"
1511        Notebook $nb text="\r"
1512        Notebook $nb text="4) Now you need to link the sample ", fStyle=2, text="transmission", fStyle=-1
1513        Notebook $nb text=" file to the sample ", fStyle=2, text="scattering", fStyle=-1
1514        Notebook $nb text=" file. Do this by selecting the name of the transmission file (from the blue T_Filenames column) and pas"
1515        Notebook $nb text="ting it into the corresponding row of the S_TRANS_Filenames column of the ScatteringFiles window. This l"
1516        Notebook $nb text="inks the scattering file to its corresponding sample transmission file. This for all of the sample scatt"
1517        Notebook $nb text="ering files.\r"
1518        Notebook $nb text="\r"
1519        Notebook $nb text="5) Calculate the transmissions (and automatically write the transmission value to the satterng file head"
1520        Notebook $nb text="er) by clicking \"Calculate All Files\" from the Transmission Panel. The results will be printed to the co"
1521        Notebook $nb text="mmand window at the bottom of the screen. Any improperly assigned files will be listed. For example, blo"
1522        Notebook $nb text="cked beam scattering files will return an error, since the transmssion known to be zero, and is not meas"
1523        Notebook $nb text="ured (and no files are \"linked\"). Rather than calculating the transmission of all of the files,  a range"
1524        Notebook $nb text=" of S_Filenames can be selected, then calculated by clicking \"Calculate Selected Files\".\r"
1525        Notebook $nb text="\r"
1526        Notebook $nb text="By default the lists are sorted by run number (= chronological). In some cases it may be easier to sort "
1527        Notebook $nb text="by the sample label to group several of the same sample scattering files collected at different sample-t"
1528        Notebook $nb text="o-detector distances. Its utility depends, of course, on how consistent and unique your sample labels ar"
1529        Notebook $nb text="e.\r"
1530        Notebook $nb text="\r"
1531        Notebook $nb text="The \"links\" are stored in the corresponding files, and wil be re-generated when the lists are re-generat"
1532        Notebook $nb text="ed. Unassigned links will appear as blank elements in the T_EMP_Filenames or S_TRANS_Filenames columns.\r"
1533        Notebook $nb text="\r"
1534        Notebook $nb, selection={startOfFile,startOfFile}
1535        Notebook $nb text="\r"
1536End
1537
1538
1539
1540//*******************
1541//************
1542//   A simple panel to allow users of the NG1 SANS instrument to make their
1543// transmission files "look" like a transmission measurement to the data reduction
1544// program. Transmission files are designated by an x-position of the beamstop of
1545// < -5 (cm). this simple procedure sets xpos=-10 for individual files. files
1546// con be "un-converted", which set the xpos=0.
1547// 1/30/01 SRK
1548//************
1549
1550Proc TransformToTransFile()
1551        Variable/G root:myGlobals:gConvTrans=1
1552        DoWindow/F Convert_to_Trans
1553        if(V_flag==0)
1554                Convert2Trans()
1555        endif
1556End
1557
1558//fname must be the full path and name for the file
1559Function ChangeBSXPos(fname,xpos)
1560        String fname
1561        Variable xpos
1562       
1563        Variable start
1564        //x-position starts after byte 368 in VAX files
1565        WriteBSXPosToHeader(fname,xpos)
1566        return(0)
1567End
1568
1569//sets the beamstop position to zero NOT the original position
1570Function UnConvertButtonProc(ctrlName) : ButtonControl
1571        String ctrlName
1572       
1573        //Print "UnConvert"
1574        String fullname=""
1575        ControlInfo fileNum
1576        Variable num = V_Value  //run number to find
1577       
1578        fullname = FindFileFromRunNumber(num)
1579        Print fullname
1580        //report error or change the file
1581        if(cmpstr(fullname,"")==0)
1582                Print "Unconvert - file not found"
1583        else
1584                //Print "Unconvert",fullname
1585                ChangeBSXPos(fullName,0)
1586        Endif
1587        return(0)
1588End
1589
1590//button procedure to do the conversion
1591// writes fake beamstop position to the data file
1592//
1593Function ConvertButtonProc(ctrlName) : ButtonControl
1594        String ctrlName
1595       
1596        String fullname=""
1597        ControlInfo fileNum
1598        Variable num = V_Value  //run number to find
1599       
1600        fullname = FindFileFromRunNumber(num)
1601        print fullname
1602        //report error or change the file
1603        if(cmpstr(fullname,"")==0)
1604                Print "Convert - file not found"
1605        else
1606                //Print "Convert",fullname
1607                ChangeBSXPos(fullName,-10)
1608        Endif
1609        return(0)
1610End
1611
1612//simple panel recreation macro
1613//
1614Proc Convert2Trans()
1615        PauseUpdate; Silent 1           // building window...
1616        NewPanel /W=(434,74,671,216) /K=1
1617        DoWindow/C Convert_to_Trans
1618        SetDrawLayer UserBack
1619        DrawText 18,22,"Convert files to be recognized"
1620        DrawText 43,39,"as transmission files"
1621        SetVariable fileNum,pos={43,58},size={130,15},title="File Number"
1622        SetVariable fileNum,limits={1,Inf,1},value=root:myGlobals:gConvTrans
1623        SetVariable fileNum,help={"Sets the run number of the file that is to be converted"}
1624        Button ConvButton,pos={73,79},size={80,20},proc=ConvertButtonProc,title="Convert"
1625        Button ConvButton,help={"Converts the chosen file to appear as a transmission file"}
1626        Button UndoButton,pos={68,105},size={90,20},proc=UnConvertButtonProc,title="Un-Convert"
1627        Button UndoButton,help={"Converts the chosen file to appear as a scattering file"}
1628EndMacro
1629
1630
1631/////
1632//  A quick way to fill all the T_EMP_Filenames with the selected empty beam file
1633// Note that you must go back and clear or reassign any files that are special cases
1634//
1635// IMPORTANT - this will overwrite any other file assignments (typically not a problem
1636// if you  are using only one wavelength)
1637//
1638/////
1639// March 2010:
1640// changed from the previous beta menu operation, now uses the text from the file name box
1641// rather than requiring a selection on the table (since you just set the box...)
1642//
1643Function FillEMPFilenameWSelection(ctrlName)
1644        String ctrlName
1645       
1646//      GetSelection table,TransFileTable,3
1647//      Variable row=V_startRow                 //ony need the selected row, we know the column names and location
1648
1649        SVAR empName = root:myGlobals:TransHeaderInfo:gEMP
1650        if(strlen(empName)==0 || cmpstr(empName,"no path selected")==0)
1651                DoAlert 0,"Please select and set an empty beam file"
1652                return(0)
1653        endif
1654        Wave/T fw = root:myGlobals:TransHeaderInfo:T_FileNames          //trans files
1655        Wave/T ew = root:myGlobals:TransHeaderInfo:T_EMP_FileNames              //empty beam reference files
1656       
1657        ew[] = empName
1658       
1659        return(0)
1660End
1661
1662//given a selection of the SAMPLE files, try to find the corresponding transmission file
1663//
1664Function GuessTransFile(charsToUse,row)
1665        Variable charsToUse,row                 //number of characers to use from the beginning of the label, and the row of the sample file
1666       
1667//      GetSelection table,ScatterFileTable,3
1668//      Variable row=V_startRow                 //ony need the selected row, we know the column names and location
1669        Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels             //Sample file labels
1670        Wave/T tw = root:myGlobals:TransHeaderInfo:T_Labels             //trans file labels
1671        Wave/T tnam = root:myGlobals:TransHeaderInfo:T_FileNames        //trans file names
1672        Wave/T snam = root:myGlobals:TransHeaderInfo:S_TRANS_FileNames  //Scattering - trans correspondence
1673       
1674        Variable num,ii,found
1675        String samStr = "",testStr=""
1676       
1677        samStr = (sw[row])[0,charsToUse-1]              //string to try and match
1678        samStr += "*"
1679//      Print samStr
1680        num=numpnts(tw)
1681        ii=0
1682        do
1683                testStr=tw[ii]
1684                found = stringmatch(testStr, samStr )
1685                if(found == 1)
1686                        Print "Match Found at:  ",samStr,tnam[ii],tw[ii]
1687                        snam[row] = tnam[ii]                    //write the file name into the table
1688                        return(0)       
1689                endif
1690                ii+=1
1691        while(ii<num)
1692       
1693        //method 2
1694//      samStr = (sw[row])[0,charsToUse-1]              //string to try and match
1695////    Print samStr
1696//      num=numpnts(tw)
1697//      ii=0
1698//      do
1699//              testStr=tw[ii]
1700//              found = strsearch(testStr,samStr,0)             //start from zero, Need Igor 5 to allow 4th parameter to ignore case
1701//              if(found != -1)
1702//                      Print "Match Found at:  ",samStr,tnam[ii],tw[ii]
1703//                      snam[row] = tnam[ii]                    //write the file name into the table
1704//                      return(0)       
1705//              endif
1706//              ii+=1
1707//      while(ii<num)
1708       
1709        Print "No Match found"
1710        return(0)
1711End
1712
1713//given a single transmission file, try to find the corresponding scattering file(s)
1714//
1715// apply TWO criteria
1716// (1) the label must match "well enough"
1717// (2) the wavelength must be the same "enough", given the unnecessary precision reported by ICE
1718//
1719// (for example, "6" can be anything from 6.0008 to 6.0020 in a recent experiment)
1720//
1721// passes the matching rows in the sample table back
1722//
1723Function GuessTransToScattFiles(charsToUse,row,matchRows)
1724        Variable charsToUse,row                 //number of characers to use from the beginning of the label, and the row of the transmission file
1725        Wave matchRows          //rows where (potential) matches found. initially zero points
1726       
1727        Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels             //Sample file labels
1728        Wave/T tw = root:myGlobals:TransHeaderInfo:T_Labels             //trans file labels
1729        Wave/T tnam = root:myGlobals:TransHeaderInfo:T_FileNames        //trans file names
1730        Wave/T snam = root:myGlobals:TransHeaderInfo:S_TRANS_FileNames  //Scattering - trans correspondence
1731        Wave sLam = root:myGlobals:TransHeaderInfo:S_Lambda             //Scattering file wavelength
1732        Wave tLam = root:myGlobals:TransHeaderInfo:T_Lambda             //Transmission file wavelength
1733       
1734        Variable num,ii,found,tolerance=0.01            //0.01 = 1% tolerance
1735        String transStr = "",testStr=""
1736       
1737        transStr = (tw[row])[0,charsToUse-1]            //string to try and match
1738        transStr += "*"
1739       
1740        //loop over ALL sample files
1741        num=numpnts(sw)
1742        ii=0
1743        do
1744                testStr=sw[ii]
1745                found = stringmatch(testStr, transStr )
1746                if( (found == 1) && (abs(sLam[ii] - tLam[row]) < tolerance) )           // both must match
1747                        Print "Match Found at:  ",transStr,snam[ii],sw[ii]
1748                        InsertPoints numpnts(matchRows), 1, matchRows
1749                        matchRows[numpnts(matchRows)-1] = ii
1750                endif
1751                ii+=1
1752        while(ii<num)
1753       
1754        //method 2 *UNTESTED*
1755//      transStr = (tw[row])[0,charsToUse-1]            //string to try and match
1756//      num=numpnts(sw)
1757//      ii=0
1758//      do
1759//              testStr=sw[ii]
1760//              found = strsearch(testStr,transStr,0,2)         //start from zero, ignore case
1761//              if(found != -1)
1762//                      Print "Match Found at:  ",transStr,snam[ii],sw[ii]
1763//                      InsertPoints numpnts(matchRows), 1, matchRows
1764//                      matchRows[numpnts(matchRows)-1] = ii
1765////                    snam[ii] = tnam[row]                    //write the file name into the table
1766//              endif
1767//              ii+=1
1768//      while(ii<num)
1769       
1770//      Print "No Match found"
1771        return(0)
1772End
1773
1774//get a single selection from the Trans table
1775// find all of the matching scattering files (rows)
1776// ask the user if the selections are OK
1777// if NOT OK, do nothing
1778// if OK: make the assignments, and immediately calculate the transmission
1779//
1780Function fGuessTransToScattFiles(numChars)
1781        Variable numChars
1782       
1783        Variable ii,row
1784        Variable transTableExists
1785        Make/O/D/N=0 root:myGlobals:TransHeaderInfo:matchRows
1786        Wave matchRows=root:myGlobals:TransHeaderInfo:matchRows
1787       
1788        transTableExists = WinType("TransFileTable")
1789        if (transTableExists != 0)
1790                GetSelection table,transFileTable,1     
1791                row = V_startRow
1792                GuessTransToScattFiles(numChars,row,matchRows)
1793        else
1794                Print "Transmission->Scattering File table is not open"
1795                return (1)
1796        endif
1797       
1798        Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels             //Sample file labels
1799        Wave/T tw = root:myGlobals:TransHeaderInfo:T_Labels             //trans file labels
1800        Wave/T tnam = root:myGlobals:TransHeaderInfo:T_FileNames        //trans file names
1801        Wave/T snam = root:myGlobals:TransHeaderInfo:S_TRANS_FileNames  //Scattering - trans correspondence
1802        Wave/T samfile = root:myGlobals:TransHeaderInfo:S_FileNames     //Scattering file name
1803       
1804        // can do fancy formatted string with ...
1805        //"asdf* matches file: \\f01filen\\f00 \\K(52428,1,1)\\f01afdsfdd\\f00\\K(0,0,0)asdfasdfs"
1806        Variable num=numpnts(matchRows)
1807        String result="",tmpStr
1808        for(ii=0;ii<num;ii+=1)
1809                sprintf tmpStr,"\\f01\\K(52428,1,1)%s\\K(0,0,0)\\f00* Matches file: \\f01%s\\f00 | \\K(52428,1,1)\\f01%s\\f00\\K(0,0,0)%s\r",(tw[row])[0,numChars-1],samfile[matchRows[ii]],(sw[matchRows[ii]])[0,numchars-1],(sw[matchRows[ii]])[numchars,59]
1810                result += tmpStr
1811        endfor
1812       
1813        if(cmpstr(result,"")==0)
1814                result = "No match found for "+ (tw[row])[0,numChars-1]
1815        endif
1816       
1817//      Print result
1818        Print "*******"
1819       
1820        String/G root:myGlobals:TransHeaderInfo:gResultStr = result
1821       
1822        DoWindow/F ConfirmGuess         //it really shouldn't exist...
1823        if(V_flag==1)
1824                TitleBox title0,pos={9,5},variable=root:myGlobals:TransHeaderInfo:gResultStr
1825        else
1826                NewPanel /W=(600,44,1150,225) as "Confirm Guess"
1827                DoWindow/C ConfirmGuess
1828                TitleBox title0,pos={15,8},size={560,32}
1829                TitleBox title0,variable= root:myGlobals:TransHeaderInfo:gResultStr
1830                Button button0,pos={9,150},size={190,20},proc=DoAssignTransButtonProc,title="Assign Transmission Files"
1831                Button button2,pos={341,150},size={90,20},proc=DoTryAgainButtonProc,title="Try Again"
1832                ToolsGrid snap=1,visible=1
1833        endif
1834       
1835        PauseForUser ConfirmGuess
1836
1837// figure out from the return code what the user did...
1838// 1 = OK, accept guess (assign, and calculate immediately)
1839// 2 = try again
1840// 0 = cancel, don't do anything (not used, simply try again)
1841        NVAR guessOK = root:myGlobals:TransHeaderInfo:GuessOK
1842       
1843        // switch here...
1844        switch(guessOK) // numeric switch
1845                case 1:         
1846                        // accept guess (assign, and calculate immediately)
1847                        for(ii=0;ii<num;ii+=1)
1848                                snam[matchRows[ii]] = tnam[row]
1849                                AssignSelTransFilesToData(matchRows[ii],matchRows[ii])
1850                                CalcSelTransFromHeader(matchRows[ii],matchRows[ii])             //does only that sample file
1851                        endfor                 
1852                        break                                           
1853                case 2: //try again (with more / fewer characters?)     
1854                        //              does nothing right now
1855                        break
1856                case 0:
1857                        // do nothing
1858                        break
1859                default:                                                       
1860                        //      do nothing                                     
1861        endswitch
1862       
1863        return(0)
1864End
1865
1866// a hook attached to the Transmission Files Table
1867// given a single selected Trans File, popup gives choices
1868// to guess using "n" characters, then dispatch accordingly
1869Function GuessFromTableHook(infoStr)
1870        String infoStr
1871        String event= StringByKey("EVENT",infoStr)
1872//      Print "EVENT= ",event
1873
1874        String menuStr=""
1875        menuStr += "Guess using N characters;"
1876        menuStr += "Guess using 3 characters;"
1877        menuStr += "Guess using 6 characters;"
1878        menuStr += "Guess using 9 characters;"
1879        menuStr += "Guess using 12 characters;"
1880        menuStr += "Guess using 15 characters;"
1881        menuStr += "Guess using 18 characters;"
1882        menuStr += "Guess using 21 characters;"
1883        menuStr += "Guess using 24 characters;"
1884       
1885        strswitch(event)
1886                case "mousedown":
1887                        Variable xpix= NumberByKey("MOUSEX",infoStr)
1888                        Variable ypix= NumberByKey("MOUSEY",infoStr)
1889                        Variable modif= NumberByKey("MODIFIERS",infoStr)
1890                        //print modif
1891                        if(modif & 2^1)         //bit 1 set, shift key is down
1892                                PopupContextualMenu/C=(xpix, ypix) menuStr
1893                                strswitch(S_selection)
1894                                        case "Guess using 3 characters":
1895                                                fGuessTransToScattFiles(3)
1896                                                break
1897                                        case "Guess using 6 characters":
1898                                                fGuessTransToScattFiles(6)
1899                                                break
1900                                        case "Guess using 9 characters":
1901                                                fGuessTransToScattFiles(9)
1902                                                break
1903                                        case "Guess using 12 characters":
1904                                                fGuessTransToScattFiles(12)
1905                                                break
1906                                        case "Guess using 15 characters":
1907                                                fGuessTransToScattFiles(15)
1908                                                break
1909                                        case "Guess using 18 characters":
1910                                                fGuessTransToScattFiles(18)
1911                                                break
1912                                        case "Guess using 21 characters":
1913                                                fGuessTransToScattFiles(21)
1914                                                break
1915                                        case "Guess using 24 characters":
1916                                                fGuessTransToScattFiles(24)
1917                                                break
1918                                        case "Guess using N characters":
1919                                                Variable num=10
1920                                                Prompt num, "Number of characters"
1921                                                DoPrompt "Enter the number of characters to match", num
1922                                                if (V_Flag)
1923                                                        break   //user cancel, do nothing
1924                                                endif
1925                                                fGuessTransToScattFiles(num)
1926                                                break
1927                                endswitch               //on selection
1928                        endif
1929        endswitch       // on event
1930       
1931        return 0
1932End
1933
1934// sets a flag if the user thinks that the guess was correct, and wants to use the
1935// identified files for the transmission
1936Function DoAssignTransButtonProc(ba) : ButtonControl
1937        STRUCT WMButtonAction &ba
1938
1939        switch( ba.eventCode )
1940                case 2: // mouse up
1941                        // click code here
1942                        //Print "Assigned stuff, and left."
1943                        Variable/G root:myGlobals:TransHeaderInfo:GuessOK= 1
1944                        DoWindow/K ConfirmGuess
1945                        break
1946        endswitch
1947
1948
1949        return 0
1950End
1951
1952// files are wrong, let the user try it again
1953// sets a flag, nothing else
1954Function DoTryAgainButtonProc(ba) : ButtonControl
1955        STRUCT WMButtonAction &ba
1956
1957        switch( ba.eventCode )
1958                case 2: // mouse up
1959                        // click code here
1960                        Variable/G root:myGlobals:TransHeaderInfo:GuessOK= 2
1961                        DoWindow/K ConfirmGuess
1962                        //Print "Try Again"
1963                        break
1964        endswitch
1965       
1966        return 0
1967End
1968
1969// not used
1970Function DoCancelGuessButtonProc(ba) : ButtonControl
1971        STRUCT WMButtonAction &ba
1972
1973        switch( ba.eventCode )
1974                case 2: // mouse up
1975                        // click code here
1976                        //just kill the panel, don't do anything
1977                        Variable/G root:myGlobals:TransHeaderInfo:GuessOK= 0
1978                        DoWindow/K ConfirmGuess
1979                        break
1980        endswitch
1981       
1982        return 0
1983End
1984
1985Function GuessAllTransFiles(numChars)
1986        Variable numChars
1987       
1988        if(WinType("ScatterFileTable") ==0 )
1989                return(1)
1990        endif
1991       
1992        Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels             //Sample file labels
1993        Variable ii,num=numpnts(sw)
1994       
1995        for(ii=0;ii<num;ii+=1)
1996                GuessTransFile(numChars,ii)
1997        endfor
1998       
1999        return(0)
2000End
2001
2002Function fGuessSelectedTransFiles(numChars)
2003        Variable numChars
2004       
2005        Variable ii
2006        Variable scatterTableExists
2007        scatterTableExists = WinType("ScatterFileTable")
2008        if (scatterTableExists != 0)
2009                GetSelection table,ScatterFileTable,1   
2010                for(ii=V_StartRow;ii<=V_EndRow;ii+=1)
2011                        GuessTransFile(numChars,ii)
2012                endfor
2013        else
2014                Print "Transmission->Scattering File table is not open"
2015        endif
2016        return(0)
2017End
2018
2019// now a button on the Transmission Panel
2020Function ClearSelectedAssignments(ctrlName)
2021        String ctrlName
2022
2023        /// old way, from the menu - takes the selection from the top window, have it now return the top table.
2024//      String winStr = WinList("*", ";", "WIN:" )              //returns the top window (with a trailing semicolon!)
2025        String winStr = WinName(0,2,1)                  //returns the top visible table
2026        Variable scatterTableExists, transTableExists
2027//      Print winStr
2028        scatterTableExists = cmpstr(winStr,"ScatterFileTable")
2029        if (scatterTableExists == 0)
2030                GetSelection table,ScatterFileTable,1   
2031                fClearSelectedAssignments(V_startRow,V_endRow,1)
2032        endif
2033       
2034        transTableExists = cmpstr(winStr,"TransFileTable")
2035        if (transTableExists == 0)
2036                GetSelection table,TransFileTable,1     
2037                fClearSelectedAssignments(V_startRow,V_endRow,2)
2038        endif
2039       
2040///////// new method, presents a clunky dialog - don't use this way unless I absolutely need to
2041//      Variable whichTable=1
2042//      Prompt whichTable,"Which Table?",popup,"Transmission Files;Scattering Files;"
2043//      DoPrompt "Which Selection to Clear",whichTable
2044//      if (V_Flag)
2045//              return 0                                                                        // user canceled
2046//      endif
2047//
2048//      if (whichTable == 1)            //the Transmission Table
2049//              GetSelection table,TransFileTable,1     
2050//              fClearSelectedAssignments(V_startRow,V_endRow,2)
2051//      else
2052//              //the Scattering Files table
2053//              GetSelection table,ScatterFileTable,1   
2054//              fClearSelectedAssignments(V_startRow,V_endRow,1)
2055//      endif
2056        return(0)
2057End
Note: See TracBrowser for help on using the repository browser.