source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_WorkFolderUtils.ipf @ 976

Last change on this file since 976 was 976, checked in by srkline, 7 years ago

Folder utilities to be able to properly move data between work folders (Duplicate w/ recursion)

Utilities to load in raw data from the main panel

Crude display of the raw data (fake, wrong dimensions) in a tabbed data panel

File size: 8.3 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2
3//
4// Functions used for manipulation of the local Igor "WORK" folder
5// structure as raw data is displayed and processed.
6//
7//
8
9
10
11//
12//Entry procedure from main panel
13//
14Proc CopyWorkFolder(oldType,newType)
15        String oldType,newType
16        Prompt oldType,"Source WORK data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;"
17        Prompt newType,"Destination WORK data type",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;STO;SUB;DRK;"
18//      Prompt oldType,"Source WORK data type",popup,"AAA;BBB;CCC;DDD;EEE;FFF;GGG;"
19//      Prompt newType,"Destination WORK data type",popup,"AAA;BBB;CCC;DDD;EEE;FFF;GGG;"
20
21        // data folder "old" will be copied to "new" (and will overwrite)
22        CopyHDFToWorkFolder(oldtype,newtype)
23End
24
25//
26// copy what is needed for data processing (not the DAS_logs)
27// from the RawVSANS storage folder to the local WORK folder as needed
28//
29// TODO -- at what stage do I make copies of data in linear/log forms for data display?
30//                      -- when do I make the 2D error waves?
31//
32// TODO - decide what exactly I need to copy over. May be best to copy all, and delete
33//       what I know that I don't need
34//
35// TODO !!! DuplicateDataFolder will FAIL - in the base case of RAW data files, the
36//  data is actually in use - so it will fail every time. need an alternate solution. in SANS,
37// there are a limited number of waves to carry over, so Dupliate/O is used for rw, tw, data, etc.
38//
39//
40//
41// TODO : I also need a list of what is generated during processing that may be hanging around - that I need to
42//     be sure to get rid of - like the calibration waves, solidAngle, etc.
43//
44// hdfDF is the name only of the data in storage. May be full file name with extension (clean as needed)
45// type is the destination WORK folder for the copy
46//
47Function CopyHDFToWorkFolder(fromStr,toStr)
48        String fromStr,toStr
49       
50        String fromDF, toDF
51       
52        // make the DF paths - source and destination
53        fromDF = "root:Packages:NIST:VSANS:"+fromStr
54        toDF = "root:Packages:NIST:VSANS:"+toStr
55       
56//      // make a copy of the file name for my own use, since it's not in the file
57//      String/G $(toDF+":file_name") = root:
58       
59        // copy the folders
60        KillDataFolder/Z toDF                   //DuplicateDataFolder will not overwrite, so Kill
61       
62        if(V_flag == 0)         // kill DF was OK
63                DuplicateDataFolder $fromDF,$toDF
64               
65                // I can delete these if they came along with RAW
66                //   DAS_logs
67                //   top-level copies of data (duplicate links)
68                KillDataFolder/Z $(toDF+":entry:entry:DAS_logs")
69                KillDataFolder/Z $(toDF+":entry:entry:data")
70                KillDataFolder/Z $(toDF+":entry:entry:data_B")
71                KillDataFolder/Z $(toDF+":entry:entry:data_ML")
72                KillDataFolder/Z $(toDF+":entry:entry:data_MR")
73                KillDataFolder/Z $(toDF+":entry:entry:data_MT")
74                KillDataFolder/Z $(toDF+":entry:entry:data_MB")
75                KillDataFolder/Z $(toDF+":entry:entry:data_FL")
76                KillDataFolder/Z $(toDF+":entry:entry:data_FR")
77                KillDataFolder/Z $(toDF+":entry:entry:data_FT")
78                KillDataFolder/Z $(toDF+":entry:entry:data_FB")
79
80                return(0)
81        else
82                // need to do this the hard way, duplicate/O recursively
83                // see V_CopyToWorkFolder()
84               
85                // everything on the top level
86                V_DuplicateDataFolder($(toDF+":entry:entry"),fromStr,toStr,0,"",0)      //no recursion here
87                // control
88                V_DuplicateDataFolder($(toDF+":entry:entry:control"),fromStr,toStr,0,"",1)      //yes recursion here
89                // instrument
90                V_DuplicateDataFolder($(toDF+":entry:entry:instrument"),fromStr,toStr,0,"",1)   //yes recursion here
91                // reduction
92                V_DuplicateDataFolder($(toDF+":entry:entry:reduction"),fromStr,toStr,0,"",1)    //yes recursion here
93                // sample
94                V_DuplicateDataFolder($(toDF+":entry:entry:sample"),fromStr,toStr,0,"",1)       //yes recursion here
95
96        endif   
97       
98        return(0)
99end
100
101
102////////
103// see the help entry for IndexedDir for help on (possibly) how to do this faster
104// -- see the function Function ScanDirectories(pathName, printDirNames)
105//
106
107
108// from IgorExchange On July 17th, 2011 jtigor
109// started from "Recursively List Data Folder Contents"
110// Posted July 15th, 2011 by hrodstein
111//
112//
113//
114Proc V_CopyToWorkFolder(dataFolderStr, fromStr, toStr, level, sNBName, recurse)
115        String dataFolderStr="root:Packages:NIST:VSANS:RAW"
116        String fromStr = "RAW"
117        String toStr="SAM"
118        Variable level=0
119        String sNBName="DataFolderTree"
120        Variable recurse = 1
121       
122        V_DuplicateDataFolder($dataFolderStr, fromStr, toStr, level, sNBName, recurse)
123
124
125end
126
127// ListDataFolder(dfr, level)
128// Recursively lists objects in data folder.
129// Pass data folder path for dfr and 0 for level.
130// pass level == 0 for the first call
131//  sNBName = "" prints nothing. any name will generate a notebook
132//
133// recurse == 0 will do only the specified folder, anything else will recurse all levels
134// toStr is the string name of the top-level folder only, not the full path
135//
136//
137Function V_DuplicateDataFolder(dfr, fromStr, toStr, level, sNBName,recurse)
138        DFREF dfr
139        String fromStr
140        String toStr
141        Variable level                  // Pass 0 to start
142        String sNBName
143        Variable recurse
144 
145        String name
146        String dfName
147        String sString
148       
149        String toDF = ""
150 
151        if (level == 0)         // this is the data folder, generate if needed in the destination
152                name = GetDataFolder(1, dfr)
153//              sPrintf sString, "%s (data folder)\r", name
154                toDF = ReplaceString(fromStr,name,toStr,1)              // case-sensitive replace
155                sprintf sString, "NewDataFolder/O %s\r",toDF
156                NewDataFolder/O $(RemoveEnding(toDF,":"))                       // remove trailing semicolon if it's there
157               
158                V_WriteBrowserInfo(sString, 1, sNBName)
159        endif
160 
161        dfName = GetDataFolder(1, dfr)
162        toDF = ReplaceString(fromStr,dfName,toStr,1)            // case-sensitive replace
163        Variable i
164 
165        String indentStr = "\t"
166        for(i=0; i<level; i+=1)
167                indentStr += "\t"
168        endfor
169 
170        Variable numWaves = CountObjectsDFR(dfr, 1)
171        for(i=0; i<numWaves; i+=1)
172                name = GetIndexedObjNameDFR(dfr, 1, i)
173                //
174                // wave type does not matter now. Duplicate does not care
175                //
176                sPrintf sString, "Duplicate/O  %s,  %s\r",dfName+name,toDF+name
177                Duplicate/O $(dfName+name),$(toDF+name)
178               
179                V_WriteBrowserInfo(sString, 2, sNBName)
180        endfor 
181 
182        Variable numNumericVariables = CountObjectsDFR(dfr, 2) 
183        for(i=0; i<numNumericVariables; i+=1)
184                name = GetIndexedObjNameDFR(dfr, 2, i)
185                sPrintf sString, "%s%s (numeric variable)\r", indentStr, name
186                V_WriteBrowserInfo(sString, 3, sNBName)
187        endfor 
188 
189        Variable numStringVariables = CountObjectsDFR(dfr, 3)   
190        for(i=0; i<numStringVariables; i+=1)
191                name = GetIndexedObjNameDFR(dfr, 3, i)
192                sPrintf sString, "%s%s (string variable)\r", indentStr, name
193                V_WriteBrowserInfo(sString, 4, sNBName)
194        endfor 
195
196        if(recurse)
197                Variable numDataFolders = CountObjectsDFR(dfr, 4)       
198                for(i=0; i<numDataFolders; i+=1)
199                        name = GetIndexedObjNameDFR(dfr, 4, i)
200//                      sPrintf sString, "%s%s (data folder)\r", indentStr, name
201                         dfName = GetDataFolder(1, dfr)
202                         
203                        toDF = ReplaceString(fromStr,dfName,toStr,1)            // case-sensitive replace
204                        sprintf sString, "NewDataFolder/O %s\r",toDF+name
205                        NewDataFolder/O $(toDF+name)
206                       
207                       
208                        V_WriteBrowserInfo(sString, 1, sNBName)
209                        DFREF childDFR = dfr:$(name)
210                        V_DuplicateDataFolder(childDFR, fromStr, toStr, level+1, sNBName, recurse)
211                endfor 
212        endif
213         
214//when finished walking tree, save as RTF with dialog   
215//      if(level == 0 && strlen(sNBName) != 0)
216//              SaveNotebook /I /S=4  $sNBName
217//      endif
218End
219 
220Function V_WriteBrowserInfo(sString, vType, sNBName)
221        String sString
222        Variable vType
223        String sNBName
224 
225        if(strlen(sNBName) == 0)
226//              print sString
227                return 0
228        endif
229        DoWindow $sNBName
230        if(V_flag != 1)
231                NewNoteBook/F=0 /N=$sNBName /V=1 as sNBName
232        else
233                DoWindow/F $sNBName
234        endif
235        Notebook $sNBName selection={endOfFile, endOfFile}
236        if(vType == 1)          // a data folder
237//              Notebook $sNBName fstyle=1
238                Notebook $sNBName text=sString
239//              Notebook $sNBName fstyle=-1
240        else
241                Notebook $sNBName text=sString 
242        endif
243 
244End
245
246///////////////////////////////
247
248
249// given the folder, duplicate the data -> linear_data and generate the error
250Function V_MakeDataError(folderStr)
251        String folderStr
252       
253        SetDataFolder $folderStr
254        Wave data=data
255        Duplicate/O data linear_data                    // at this point, the data is still the raw data, and is linear_data
256       
257        // proper error for counting statistics, good for low count values too
258        // rather than just sqrt(n)
259        // see N. Gehrels, Astrophys. J., 303 (1986) 336-346, equation (7)
260        // for S = 1 in eq (7), this corresponds to one sigma error bars
261        Duplicate/O linear_data linear_data_error
262        linear_data_error = 1 + sqrt(linear_data + 0.75)                               
263        //
264       
265        SetDataFolder root:
266        return(0)
267End
Note: See TracBrowser for help on using the repository browser.