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

Last change on this file since 890 was 888, checked in by srkline, 10 years ago

Changes to utility functions to properly list the raw data from the 10m SANS (SA4)

Added a utility function to patch BS xPos in 10m data files so that they will be recognized as transmission files. ICE is currently not writing out the BS xPos to the file. This is done in batch mode, similar to what was done for the 8m SANS.

Some changes to the simulation code to permit easier scripting.

Additions to SASCALC for the 10m SANS. Dimensions from John. Still need attenuator table and flux.

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