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

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

minor changes to prefix functions with "V_" to avoid conflicts with non-VSANS functions.

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