source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_FileCatalog.ipf @ 1037

Last change on this file since 1037 was 1037, checked in by srkline, 6 years ago

added a simple reader for .itx files that saved individual panel data. (still need to write the plotting routine)

  • Property svn:executable set to *
File size: 33.3 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5//
6// UPDATED for VSANS - only the simplest implementation to start with
7// June 2016  SRK
8// included ANSTO sort panel from david m
9//
10
11
12//
13// TODO
14// -- clean up and remove all of the references to other facilities, since they will not have VSANS modules
15// -- add in more appropriate and some missing fields more useful to VSANS (intent, multiple beam centers, etc.)
16// -- can I make the choice of columns customizable? There are "sets" of columns that are not used for
17//    some experiments (magnetic, rotation, temperature scans, etc.) but are necessary for others.
18//
19// TODO PRIORITY:
20// x- clean up the list of files that now accumulates in the RawVSANS folder!!! Everything is there, including
21//    files that are NOT RAW VSANS data (MASK and DIV, but these are HDF)
22// x- WHY -- because if I PATCH anything, then re-run the catalog, the changes are NOT shown, since the
23//    reader will go to the LOCAL copy first! So maybe I need to clear the folder out before I start the
24//    file catalog
25// x- maybe it's a good thing to wipe out the RawVSANS folder before an Experiment SAVE (to save a LOT of
26//    space on disk and a potentially VERY long save
27// x- see V_CleanOutRawVSANS() in V_Utilities_General for the start of this (this is now called in
28//    V_BuildCatVeryShortTable(), the starting point for generating the table.)
29//
30// NEW for VSANS
31// clear out the folders in the RawVSANS folder, otherwise any changes/patches written to disk
32// will not be read in, the "bad" local copy will be read in.
33// TODO:
34//  -- this *may* be a very slow operation. Warn users. Give them a choice to keep local copies. If
35//     the "patched" values are written locally too, then maybe the update from disk is not needed.
36//     But typically, I'd like to see that the disk version really did get updated...
37// -- make a background task to periodically "kill" a few of the files? maybe too dangerous.
38// -- change the V_GetHeaderInfoToWave function to allow "refreshing" of a single row, say after
39//    a file has been patched - then the disk and local copies are in sync
40//
41// -- run a profiler on the catalog to see if there is an obvious place to speed up the process
42//
43
44Function catalogProfiler()
45        V_BuildCatVeryShortTable()
46End
47
48//
49//      SRK modified 30 JAN07 to include Rotation angle, Temperature, and B-field in the table (at the end)
50//
51
52//**************
53// Vers 1.2 090401
54//
55// Procedures for creating the Catalog listings of the SANS datafiles in the folder
56// specified by catPathName.
57// Header information from each of the dataifles is organized in a table for
58// easy identification of each file. CatVSANSTable is the preferred invocation,
59// although CatVSNotebook and CatNotebook can also be used.
60// Files in the folder that are not RAW SANS data are appended to the end of the listing.
61//**************
62
63//this main procedure does all the work, obtaining the folder path,
64//parsing the filenames in the list and (dispatching) to write out the
65//appropriate information to the growing (table) of data. V_GetHeaderInfoToWave() does the individual reads
66Function V_BuildCatVeryShortTable()
67       
68        Variable err
69        Variable t1 = ticks
70       
71        PathInfo catPathName
72        if(v_flag==0)
73                err = V_PickPath()              //sets the local path to the data (catPathName)
74                if(err)
75                        Abort "no path to data was selected, no catalog can be made - use PickPath button"
76                Endif
77        Endif
78       
79        DoWindow/F CatVSANSTable
80       
81        Make/O/T/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames"
82//      Make/O/T/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Suffix"
83        Make/O/T/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Labels"
84        Make/O/T/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:DateAndTime"
85//      Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:SDD"
86        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Lambda"
87        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntTime"
88        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:TotCnts"
89        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntRate"
90        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Transmission"
91        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Thickness"
92//      Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:XCenter"
93//      Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:YCenter"
94        Make/O/T/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:nGuides"
95        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:NumAttens"
96//      Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:RunNumber"
97//      Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:IsTrans"
98        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:RotAngle"
99        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Temperature"
100        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Field"
101        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:MCR"            //added Mar 2008
102        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Pos"            //added Mar 2010
103        Make/O/T/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent"
104        Make/O/D/N=0 $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Group_ID"
105
106
107        WAVE/T Filenames = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames"
108//      WAVE/T Suffix = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Suffix"
109        WAVE/T Labels = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Labels"
110        WAVE/T DateAndTime = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:DateAndTime"
111//      WAVE SDD = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:SDD"
112        WAVE Lambda = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Lambda"
113        WAVE CntTime = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntTime"
114        WAVE TotCnts = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:TotCnts"
115        WAVE CntRate = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntRate"
116        WAVE Transmission = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Transmission"
117        WAVE Thickness = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Thickness"
118//      WAVE XCenter = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:XCenter"
119//      WAVE YCenter = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:YCenter"
120
121        WAVE/T nGuides = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:nGuides"
122        WAVE NumAttens = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:NumAttens"
123//      WAVE RunNumber = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:RunNumber"
124//      WAVE IsTrans = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:IsTrans"
125        WAVE RotAngle = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:RotAngle"
126        WAVE Temperature = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Temperature"
127        WAVE Field = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Field"
128        WAVE MCR = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:MCR"              //added Mar 2008
129        WAVE Pos = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Pos"
130        WAVE/T Intent = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent"
131        WAVE Group_ID = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Group_ID"
132
133       
134        If(V_Flag==0)
135                V_BuildTableWindow()
136//              ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:SDD)=40
137                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:Lambda)=40
138                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:CntTime)=50
139                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:TotCnts)=60
140                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:CntRate)=60
141                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:Transmission)=40
142                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:Thickness)=40
143//              ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:XCenter)=40
144//              ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:YCenter)=40
145                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:NumAttens)=30
146                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:RotAngle)=50
147                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:Field)=50
148                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:MCR)=50
149
150                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:nGuides)=40
151                ModifyTable width(root:Packages:NIST:VSANS:CatVSHeaderInfo:Pos)=30
152                ModifyTable sigDigits(root:Packages:NIST:VSANS:CatVSHeaderInfo:Pos)=3                   //to make the display look nice, given the floating point values from ICE
153                ModifyTable sigDigits(root:Packages:NIST:VSANS:CatVSHeaderInfo:Lambda)=3                //may not work in all situations, but an improvement
154//              ModifyTable sigDigits(root:Packages:NIST:VSANS:CatVSHeaderInfo:SDD)=5
155                ModifyTable trailingZeros(root:Packages:NIST:VSANS:CatVSHeaderInfo:Temperature)=1
156                ModifyTable sigDigits(root:Packages:NIST:VSANS:CatVSHeaderInfo:Temperature)=4
157
158                ModifyTable width(Point)=0              //JUN04, remove point numbers - confuses users since point != run
159
160// TODO:
161//  -- experimental hook with contextual menu
162//             
163                SetWindow kwTopWin hook=V_CatTableHook, hookevents=1    // mouse down events
164
165        Endif
166
167
168// NEW for VSANS
169// clear out the folders in the RawVSANS folder, otherwise any changes/patches written to disk
170// will not be read in, the "bad" local copy will be read in for any subsequent operations.
171// TODO:
172//  -- this *may* be a very slow operation. Warn users. Give them a choice to keep local copies? If
173//     the "patched" values are written locally too, then maybe the update from disk is not needed.
174//     But typically, I'd like to see that the disk version really did get updated...
175//
176        //      V_CleanOutRawVSANS()
177// This will display a progress bar
178        Variable numToClean
179        numToClean = V_CleanupData_w_Progress(0,1)
180
181        Print "Cleaned # files = ",numToClean
182        Print "Cleanup time (s) = ",(ticks - t1)/60.15
183        Variable cleanupTime = (ticks - t1)/60.15
184
185        //get a list of all files in the folder, some will be junk version numbers that don't exist     
186        String list,partialName,tempName,temp=""
187        list = IndexedFile(catPathName,-1,"????")       //get all files in folder
188        Variable numitems,ii,ok
189       
190        numitems = ItemsInList(list,";")
191       
192        //loop through all of the files in the list, reading CAT/SHORT information if the file is RAW SANS
193        //***version numbers have been removed***
194        String str,fullName
195        Variable lastPoint
196        ii=0
197       
198        Make/T/O/N=0 notRAWlist
199        do
200       
201                //get current item in the list
202                partialName = StringFromList(ii, list, ";")
203                //get a valid file based on this partialName and catPathName
204                tempName = V_FindValidFilename(partialName)
205               
206               
207                If(cmpstr(tempName,"")==0)              //a null string was returned
208                        //write to notebook that file was not found
209                        //if string is not a number, report the error
210                        if(numtype(str2num(partialName)) == 2)
211                                str = "this file was not found: "+partialName+"\r\r"
212                                //Notebook CatWin,font="Times",fsize=12,text=str
213                        Endif
214                else
215                        //prepend path to tempName for read routine
216                        PathInfo catPathName
217                        FullName = S_path + tempName
218                        //make sure the file is really a RAW data file
219                        ok = V_CheckIfRawData(fullName)
220               
221                        if (!ok)
222                                //write to notebook that file was not a RAW SANS file
223                                lastPoint = numpnts(notRAWlist)
224                                InsertPoints lastPoint,1,notRAWlist
225                                notRAWlist[lastPoint]=tempname
226                        else
227                                //go write the header information to the Notebook
228                                V_GetHeaderInfoToWave(fullName,tempName)
229                        Endif
230                Endif
231                ii+=1
232        while(ii<numitems)
233//Now sort them all based on some criterion that may be facility dependent (aim is to order them as collected)
234        V_SortWaves()
235//Append the files that are not raw files to the list
236        V_AppendNotRAWFiles(notRAWlist)
237        KillWaves/Z notRAWlist
238//
239        Print "Total time (s) = ",(ticks - t1)/60.15
240        Print "Time per raw data file (without cleanup time) (s) = ",( (ticks - t1)/60.15 - cleanupTime)/(numItems-numpnts(labels))
241        // (don't use numpnts(notRawList) to normalize, these aren't all raw data files)
242        //
243        // clean out again, so that the file SAVE is not slow due to the large experiment size
244        // TODO -- decide if this is really necessary
245//     
246//      V_CleanOutRawVSANS()
247                       
248                       
249        return(0)
250End
251
252//
253// TODO:
254//  this is experimental...not been tested by any users yet
255// -- what else to add to the menu? (MSK and DIV now work)
256// -- add directly to WORK files?
257// -- "set" as some special file type, intent, use?
258// -- "check" the reduction protocol for completeness?
259//
260// x- seems to not "let go" of a selection (missing the mouse up?)
261//    (possibly) less annoying if I only handle mouseup and present a menu then.
262//
263Function V_CatTableHook(infoStr)
264        String infoStr
265        String event= StringByKey("EVENT",infoStr)
266//      Print "EVENT= ",event
267        strswitch(event)
268                case "mouseup":
269//                      Variable xpix= NumberByKey("MOUSEX",infoStr)
270//                      Variable ypix= NumberByKey("MOUSEY",infoStr)
271//                      PopupContextualMenu/C=(xpix, ypix) "yes;no;maybe;"
272                        PopupContextualMenu "Load RAW;Load MSK;Load DIV;"
273                       
274                        WAVE/T Filenames = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames"
275                        Variable err
276                        strswitch(S_selection)
277                                case "Load RAW":
278                                        GetSelection table,CatVSANSTable,1
279//                                      Print V_flag, V_startRow, V_startCol, V_endRow, V_endCol
280                                        Print "Loading " + FileNames[V_StartRow]
281                                        err = V_LoadHDF5Data(FileNames[V_StartRow],"RAW")
282                                        if(!err)                //directly from, and the same steps as DisplayMainButtonProc(ctrlName)
283                                                SVAR hdfDF = root:file_name                     // last file loaded, may not be the safest way to pass
284                                                String folder = StringFromList(0,hdfDF,".")
285                                               
286                                                // this (in SANS) just passes directly to fRawWindowHook()
287                                                V_UpdateDisplayInformation("RAW")               // plot the data in whatever folder type
288                                                                                               
289                                                // set the global to display ONLY if the load was called from here, not from the
290                                                // other routines that load data (to read in values)
291                                                SVAR gLast = root:Packages:NIST:VSANS:Globals:gLastLoadedFile
292                                                gLast = hdfDF
293                                               
294                                        endif
295                                        break;
296                                       
297                                case "Load MSK":
298                                        GetSelection table,CatVSANSTable,1
299//                                      Print V_flag, V_startRow, V_startCol, V_endRow, V_endCol
300                                        Print "Loading " + FileNames[V_StartRow]
301                                        err = V_LoadHDF5Data(FileNames[V_StartRow],"MSK")
302                                       
303                                        break;
304                                       
305                                case "Load DIV":
306                                        GetSelection table,CatVSANSTable,1
307//                                      Print V_flag, V_startRow, V_startCol, V_endRow, V_endCol
308                                        Print "Loading " + FileNames[V_StartRow]
309                                        err = V_LoadHDF5Data(FileNames[V_StartRow],"DIV")
310
311                                        break;
312                                       
313                        endswitch               //popup selection
314        endswitch       // event
315       
316        return 0
317End
318
319
320
321//appends the list of files that are not RAW SANS data to the filename wave (1st column)
322//for display in the table. Note that the filenames column will now be longer than all other
323//waves in the table
324Function V_AppendNotRAWFiles(w)
325        Wave/T w
326        Wave/T Filenames = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames"
327        Variable lastPoint
328        lastPoint = numpnts(Filenames)
329        InsertPoints lastPoint,numpnts(w),Filenames
330        Filenames[lastPoint,numpnts(Filenames)-1] = w[p-lastPoint]
331        return(0)
332End
333
334//sorts all of the waves of header information using the suffix (A123)
335//the result is that all of the data is in the order that it was collected,
336// regardless of how the prefix or run numbers were changed by the user
337Function V_SortWaves()
338        Wave/T GFilenames = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames"
339//      Wave/T GSuffix = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Suffix"
340        Wave/T GLabels = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Labels"
341        Wave/T GDateTime = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:DateAndTime"
342//      Wave GSDD = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:SDD"
343        Wave GLambda = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Lambda"
344        Wave GCntTime = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntTime"
345        Wave GTotCnts = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:TotCnts"
346        Wave GCntRate = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntRate"
347        Wave GTransmission = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Transmission"
348        Wave GThickness = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Thickness"
349//      Wave GXCenter = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:XCenter"
350//      Wave GYCenter = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:YCenter"
351
352        Wave/T GNumGuides = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:nGuides"
353        Wave GNumAttens = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:NumAttens"
354//      Wave GRunNumber = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:RunNumber"
355//      Wave GIsTrans = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:IsTrans"
356        Wave GRot = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:RotAngle"
357        Wave GTemp = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Temperature"
358        Wave GField = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Field"
359        Wave GMCR = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:MCR"             //added Mar 2008
360        Wave GPos = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Pos"
361        Wave/T GIntent = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent"
362        Wave G_ID = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Group_ID"
363
364
365// DONE
366// x- the default sort is by SUFFIX, which does not exist for VSANS. So decide on a better key
367//     now, the sort is by FileName by default
368//      Sort GFilenames, GSuffix, GFilenames, GLabels, GDateTime, GSDD, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness, GXCenter, GYCenter, GNumAttens,GRunNumber,GIsTrans,GRot,GTemp,GField,GMCR,GPos,gNumGuides
369        Sort GFilenames, GFilenames, GLabels, GDateTime,  GIntent, G_ID, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,GRot,GTemp,GField,GMCR,GPos,gNumGuides
370
371        return(0)
372End
373
374//function to create the CAT/VSTable to display the header information
375//this table is just like any other table
376Function V_BuildTableWindow()
377        Wave/T Filenames = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames"
378        Wave/T Labels = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Labels"
379        Wave/T DateAndTime = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:DateAndTime"
380//      Wave SDD = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:SDD"
381        Wave Lambda = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Lambda"
382        Wave CntTime = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntTime"
383        Wave TotCnts = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:TotCnts"
384        Wave CntRate = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntRate"
385        Wave Transmission = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Transmission"
386        Wave Thickness = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Thickness"
387//      Wave XCenter = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:XCenter"
388//      Wave YCenter = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:YCenter"
389
390        Wave/T NumGuides = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:nGuides"
391        Wave NumAttens = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:NumAttens"
392        Wave RotAngle =  $"root:Packages:NIST:VSANS:CatVSHeaderInfo:RotAngle"
393        Wave Temperature = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Temperature"
394        Wave Field= $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Field"
395        Wave MCR = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:MCR"              //added Mar 2008
396        Wave Pos = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Pos"
397        Wave/T Intent = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent"
398        Wave Group_ID = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Group_ID"
399
400// original order, magnetic at the end
401//      Edit Filenames, Labels, DateAndTime, SDD, Lambda, CntTime, TotCnts, CntRate, Transmission, Thickness, XCenter, YCenter, NumAttens, RotAngle, Temperature, Field, MCR as "Data File Catalog"
402// with numGuides
403//      Edit Filenames, Labels, DateAndTime, SDD, Lambda, numGuides, CntTime, TotCnts, CntRate, Transmission, Thickness, XCenter, YCenter, NumAttens, RotAngle, Temperature, Field, MCR, Pos as "Data File Catalog"
404        Edit Filenames, Labels, DateAndTime,  Intent, Group_ID, Lambda, numGuides, CntTime, TotCnts, CntRate, Transmission, Thickness, NumAttens, RotAngle, Temperature, Field, MCR, Pos as "Data File Catalog"
405
406
407        String name="CatVSANSTable"
408        DoWindow/C $name
409        return(0)
410End
411
412//reads header information and puts it in the appropriate waves for display in the table.
413//fname is the full path for opening (and reading) information from the file
414//which alreay was found to exist. sname is the file;vers to be written out,
415//avoiding the need to re-extract it from fname.
416Function V_GetHeaderInfoToWave(fname,sname)
417        String fname,sname
418       
419
420        Variable lastPoint,ctime,detcnt,cntrate
421
422        Wave/T GFilenames = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames"
423//      Wave/T GSuffix = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Suffix"
424        Wave/T GLabels = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Labels"
425        Wave/T GDateTime = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:DateAndTime"
426
427//      Wave GSDD = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:SDD"
428        Wave GLambda = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Lambda"
429        Wave GCntTime = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntTime"
430        Wave GTotCnts = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:TotCnts"
431        Wave GCntRate = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntRate"
432        Wave GTransmission = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Transmission"
433        Wave GThickness = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Thickness"
434//      Wave GXCenter = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:XCenter"
435//      Wave GYCenter = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:YCenter"
436        Wave/T GNumGuides = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:nGuides"
437        Wave GNumAttens = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:NumAttens"
438//      Wave GRunNumber = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:RunNumber"
439//      Wave GIsTrans = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:IsTrans"
440        Wave GRot = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:RotAngle"
441        Wave GTemp = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Temperature"
442        Wave GField = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Field"
443        Wave GMCR = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:MCR"
444        Wave GPos = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Pos"
445        Wave/T GIntent = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent"
446        Wave G_ID = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Group_ID"
447
448        lastPoint = numpnts(GLambda)
449               
450        //filename
451        InsertPoints lastPoint,1,GFilenames
452        GFilenames[lastPoint]=sname
453       
454//      //read the file alphanumeric suffix
455//      // TODO -- this does not exist for VSANS - so is there an equivalent, or delete?
456//      InsertPoints lastPoint,1,GSuffix
457//      GSuffix[lastPoint]="unknown"
458
459        //read the counting time (integer)
460        InsertPoints lastPoint,1,GCntTime
461        ctime = V_getCount_time(fname)
462        GCntTime[lastPoint]=ctime
463       
464        //read the file creation date (string)
465        InsertPoints lastPoint,1,GDateTime
466        GDateTime[lastPoint]=V_getDataStartTime(fname)
467
468        // read the sample.label text field (string)
469        InsertPoints lastPoint,1,GLabels
470        GLabels[lastPoint]=V_getSampleDescription(fname)
471       
472               
473        //read the reals
474        //detector count and (derived) count rate
475        // TODO -- this is hard-wired for a single detector, which is WRONG
476        detcnt = V_getDet_IntegratedCount(fname,"FL")
477        cntrate = detcnt/ctime
478        InsertPoints lastPoint,1,GTotCnts
479        GTotCnts[lastPoint]=detcnt
480        InsertPoints lastPoint,1,GCntRate
481        GCntRate[lastPoint]=cntrate
482       
483        //Attenuators
484        // TODO -- this is not really the number --
485        InsertPoints lastPoint,1,GNumAttens
486        GNumAttens[lastPoint]=V_getAttenThickness(fname)
487       
488        //Transmission
489        InsertPoints lastPoint,1,GTransmission
490        GTransmission[lastPoint]=V_getSampleTransmission(fname)
491       
492        //Thickness
493        InsertPoints lastPoint,1,GThickness
494        GThickness[lastPoint]=V_getSampleThickness(fname)
495
496//      // TODO --  the x and y center have different meaning, since there are multiple panels
497//      // TODO -- remove the hard-wiring
498//      String detStr = "FL"
499//      //XCenter of beam on detector
500//      InsertPoints lastPoint,1,GXCenter
501//      GXCenter[lastPoint]=V_getDet_beam_center_x(fname,detStr)
502//     
503//      // TODO --  the x and y center have different meaning, since there are multiple panels
504//      //YCenter
505//      InsertPoints lastPoint,1,GYCenter
506//      GYCenter[lastPoint]=V_getDet_beam_center_y(fname,detStr)
507
508//      // TODO -- SDD has no real meaning - since there are multiple distances to report
509//      //SDD
510//      InsertPoints lastPoint,1,GSDD
511//      GSDD[lastPoint]=V_getDet_ActualDistance(fname,detStr)
512       
513        //wavelength
514        InsertPoints lastPoint,1,GLambda
515        GLambda[lastPoint]=V_getWavelength(fname)
516       
517        //Rotation Angle
518        InsertPoints lastPoint,1,GRot
519        GRot[lastPoint]=V_getSampleRotationAngle(fname)
520       
521        // TODO -- this is not yet implemented
522        //Sample Temperature
523        InsertPoints lastPoint,1,GTemp
524        GTemp[lastPoint]=-273
525
526        // TODO -- this is not yet implemented
527        //Sample Field
528        InsertPoints lastPoint,1,GField
529        GField[lastPoint]=1000
530       
531
532//      //the run number (not displayed in the table, but carried along)
533//      InsertPoints lastPoint,1,GRunNumber
534//      GRunNumber[lastPoint] = V_GetRunNumFromFile(sname)
535//
536//      // TODO -- the isTransFile utility has not yet been written
537//      // 0 if the file is a scattering  file, 1 (truth) if the file is a transmission file
538//      InsertPoints lastPoint,1,GIsTrans
539//      GIsTrans[lastPoint]  = V_isTransFile(fname)             //returns one if beamstop is "out"
540       
541        // Monitor Count Rate
542        InsertPoints lastPoint,1,GMCR
543        GMCR[lastPoint]  = V_getMonitorCount(fname)/ctime               //total monitor count / total count time
544
545
546// number of guides and sample position, only for NCNR (a string now)
547        InsertPoints lastPoint,1,GNumGuides
548        GNumGuides[lastPoint]  = V_getNumberOfGuides(fname)
549
550// TODO -- maybe this is better to convert to a text wave?     
551        //Sample Position (== number position in 10CB)
552        InsertPoints lastPoint,1,GPos
553        GPos[lastPoint] = str2num(V_getSamplePosition(fname))
554
555// Intent (text)
556        InsertPoints lastPoint,1,GIntent
557        GIntent[lastPoint] = V_getReduction_intent(fname)
558       
559// group_id (sample)
560        InsertPoints lastPoint,1,G_ID
561        G_ID[lastPoint] = V_getSample_groupID(fname)
562
563        return(0)
564End
565
566
567
568// just to call the function to generate the panel
569Proc V_Catalog_Sort()
570        V_BuildCatSortPanel()
571End
572
573// [davidm] create CAT Sort-Panel
574function V_BuildCatSortPanel()
575
576        // check if CatVSANSTable exists
577        DoWindow CatVSANSTable
578        if (V_flag==0)
579                DoAlert 0,"There is no File Catalog table. Use the File Catalog button to create one."
580                return 0
581        endif
582       
583        // bring CatSortPanel to front
584        DoWindow/F CatSortPanel
585        if (V_flag != 0)
586                return 0
587        endif
588       
589        print "Creating CAT Sort-Panel..."
590               
591        //PauseUpdate
592        NewPanel /W=(600,360,790,730)/K=1 as "CAT - Sort Panel"
593        DoWindow/C CatSortPanel
594        ModifyPanel fixedSize=1, cbRGB = (42919, 53970, 60909)
595       
596        Button SortFilenamesButton,             pos={25, 8},            size={140,24},proc=V_CatVSANSTable_SortProc,title="Filenames"
597        Button SortLabelsButton,                        pos={25,38},            size={140,24},proc=V_CatVSANSTable_SortProc,title="Labels"
598        Button SortDateAndTimeButton,   pos={25,68},            size={140,24},proc=V_CatVSANSTable_SortProc,title="Date and Time"
599        Button SortIntentButton,                        pos={25,98},            size={140,24},proc=V_CatVSANSTable_SortProc,title="Intent"
600        Button SortIDButton,                    pos={25,128},   size={140,24},proc=V_CatVSANSTable_SortProc,title="Group ID"
601        Button SortLambdaButton,                        pos={25,158},   size={140,24},proc=V_CatVSANSTable_SortProc,title="Lambda"
602        Button SortCountTimButton,              pos={25,188},   size={140,24},proc=V_CatVSANSTable_SortProc,title="Count Time"
603        Button SortTotalCountsButton,           pos={25,218},   size={140,24},proc=V_CatVSANSTable_SortProc,title="Total Counts"
604        Button SortCountRateButton,             pos={25,248},   size={140,24},proc=V_CatVSANSTable_SortProc,title="Count Rate"
605        Button SortMonitorCountsButton, pos={25,278},   size={140,24},proc=V_CatVSANSTable_SortProc,title="Monitor Counts"
606        Button SortTransmissionButton,  pos={25,308},   size={140,24},proc=V_CatVSANSTable_SortProc,title="Transmission"
607        Button SortThicknessButton,             pos={25,338},   size={140,24},proc=V_CatVSANSTable_SortProc,title="Thickness"
608
609end
610
611Proc V_CatVSANSTable_SortProc(ctrlName) : ButtonControl // added by [davidm]
612        String ctrlName
613       
614        // check if CatVSANSTable exists
615        DoWindow CatVSANSTable
616        if (V_flag==0)
617                DoAlert 0,"There is no File Catalog table. Use the File Catalog button to create one."
618                return
619        endif
620               
621        // have to use function
622        V_CatVSANSTable_SortFunction(ctrlName)
623       
624end
625
626function V_CatVSANSTable_SortFunction(ctrlName) // added by [davidm]
627        String ctrlName
628
629        Wave/T GFilenames = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Filenames"
630//      Wave/T GSuffix = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Suffix"
631        Wave/T GLabels = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Labels"
632        Wave/T GDateTime = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:DateAndTime"
633//      Wave GSDD = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:SDD"
634        Wave GLambda = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Lambda"
635        Wave GCntTime = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntTime"
636        Wave GTotCnts = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:TotCnts"
637        Wave GCntRate = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:CntRate"
638        Wave GTransmission = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Transmission"
639        Wave GThickness = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Thickness"
640//      Wave GXCenter = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:XCenter"
641//      Wave GYCenter = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:YCenter"
642        Wave/T GNumGuides = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:nGuides"
643        Wave GNumAttens = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:NumAttens"
644//      Wave GRunNumber = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:RunNumber"
645//      Wave GIsTrans = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:IsTrans"
646        Wave GRot = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:RotAngle"
647        Wave GTemp = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Temperature"
648        Wave GField = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Field"
649        Wave GMCR = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:MCR"
650        Wave GPos = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Pos"
651        Wave/T GIntent = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Intent"
652        Wave G_ID = $"root:Packages:NIST:VSANS:CatVSHeaderInfo:Group_ID"
653
654       
655        // take out the "not-RAW-Files"
656        Variable fileCount = numpnts(GFilenames)
657        Variable rawCount = numpnts(GLabels)
658        Variable notRAWcount = fileCount - rawCount
659       
660        if (notRAWcount > 0)
661                Make/T/O/N=(notRAWcount) notRAWlist
662                notRAWlist[0, notRAWcount-1] = GFilenames[p+rawCount]
663                DeletePoints rawCount, notRAWcount, GFilenames
664        endif
665       
666        strswitch (ctrlName)
667       
668                case "SortFilenamesButton":
669//                      Sort GFilenames, GSuffix, GFilenames, GLabels, GDateTime, GSDD, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness, GXCenter, GYCenter, GNumAttens, GRunNumber, GIsTrans, GRot, GTemp, GField, GMCR
670                        Sort GFilenames,  GFilenames, GLabels, GDateTime,  GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,   GRot, GTemp, GField, GMCR, GIntent, G_ID
671                        break
672                       
673                case "SortLabelsButton":
674//                      Sort GLabels, GSuffix, GFilenames, GLabels, GDateTime, GSDD, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness, GXCenter, GYCenter, GNumAttens, GRunNumber, GIsTrans, GRot, GTemp, GField, GMCR
675                        Sort GLabels,  GFilenames, GLabels, GDateTime,  GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,   GRot, GTemp, GField, GMCR, GIntent, G_ID
676                        break
677                       
678                case "SortDateAndTimeButton":
679//                      Sort GDateTime, GSuffix, GFilenames, GLabels, GDateTime, GSDD, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness, GXCenter, GYCenter, GNumAttens, GRunNumber, GIsTrans, GRot, GTemp, GField, GMCR
680                        Sort GDateTime,  GFilenames, GLabels, GDateTime,  GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,   GRot, GTemp, GField, GMCR, GIntent, G_ID
681
682                        break
683                       
684                case "SortIntentButton":
685                        Sort GIntent,  GFilenames, GLabels, GDateTime,  GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,   GRot, GTemp, GField, GMCR, GIntent, G_ID
686                        break
687                       
688                case "SortIDButton":
689                        Sort G_ID,  GFilenames, GLabels, GDateTime,  GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,   GRot, GTemp, GField, GMCR, GIntent, G_ID
690                        break
691                       
692                case "SortLambdaButton":
693//                      Sort GLambda, GSuffix, GFilenames, GLabels, GDateTime, GSDD, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness, GXCenter, GYCenter, GNumAttens, GRunNumber, GIsTrans, GRot, GTemp, GField, GMCR
694                        Sort GLambda,  GFilenames, GLabels, GDateTime,  GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,   GRot, GTemp, GField, GMCR, GIntent, G_ID
695
696                        break
697                       
698                case "SortCountTimButton":
699//                      Sort GCntTime, GSuffix, GFilenames, GLabels, GDateTime, GSDD, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness, GXCenter, GYCenter, GNumAttens, GRunNumber, GIsTrans, GRot, GTemp, GField, GMCR
700                        Sort GCntTime,  GFilenames, GLabels, GDateTime,  GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,   GRot, GTemp, GField, GMCR, GIntent, G_ID
701
702                        break
703                       
704                case "SortTotalCountsButton":
705//                      Sort GTotCnts, GSuffix, GFilenames, GLabels, GDateTime, GSDD, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness, GXCenter, GYCenter, GNumAttens, GRunNumber, GIsTrans, GRot, GTemp, GField, GMCR
706                        Sort GTotCnts,  GFilenames, GLabels, GDateTime,  GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,   GRot, GTemp, GField, GMCR, GIntent, G_ID
707
708                        break
709                       
710                case "SortCountRateButton":
711//                      Sort GCntRate, GSuffix, GFilenames, GLabels, GDateTime, GSDD, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness, GXCenter, GYCenter, GNumAttens, GRunNumber, GIsTrans, GRot, GTemp, GField, GMCR
712                        Sort GCntRate,  GFilenames, GLabels, GDateTime,  GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,   GRot, GTemp, GField, GMCR, GIntent, G_ID
713
714                        break
715                       
716                case "SortMonitorCountsButton":
717                        break
718                       
719                case "SortTransmissionButton":
720//                      Sort GTransmission, GSuffix, GFilenames, GLabels, GDateTime, GSDD, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness, GXCenter, GYCenter, GNumAttens, GRunNumber, GIsTrans, GRot, GTemp, GField, GMCR
721                        Sort GTransmission,  GFilenames, GLabels, GDateTime,  GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,   GRot, GTemp, GField, GMCR, GIntent, G_ID
722
723                        break
724                       
725                case "SortThicknessButton":
726//                      Sort GThickness, GSuffix, GFilenames, GLabels, GDateTime, GSDD, GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness, GXCenter, GYCenter, GNumAttens, GRunNumber, GIsTrans, GRot, GTemp, GField, GMCR
727                        Sort GThickness,  GFilenames, GLabels, GDateTime,  GLambda, GCntTime, GTotCnts, GCntRate, GTransmission, GThickness,   GNumAttens,   GRot, GTemp, GField, GMCR, GIntent, G_ID
728
729                        break
730       
731        endswitch
732       
733        // insert the "not-RAW-Files" again
734        if (notRAWcount > 0)
735                InsertPoints rawCount, notRAWcount, GFilenames
736                GFilenames[rawCount, fileCount-1] = notRAWlist[p-rawCount]
737        endif
738end
Note: See TracBrowser for help on using the repository browser.