source: sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/Transmission.ipf @ 80

Last change on this file since 80 was 75, checked in by srkline, 16 years ago

Final set of first pass changes to reduction code. Next is to throuroughly test before heading to the second pass of non-obvious function calls and documentation of the "required" stubs for a particular file type.

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