source: sans/SANSReduction/trunk/Put in User Procedures/SANS_Reduction_v5.00/Transmission.ipf @ 116

Last change on this file since 116 was 116, checked in by ajj, 15 years ago

Merged kline_29MAR07 branch (Separation of NCNR specific code) r66:115 into the trunk

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