source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Initialize.ipf @ 1051

Last change on this file since 1051 was 1051, checked in by srkline, 5 years ago

a lot of little changes:

changed the name of the Raw Data display procedure file (removed test)

lots of bug fixes, moving items from the macros menu to proper locations, getting the file status to display properly, some error checking, and cleaning up a few TODO items.

File size: 12.8 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2#pragma version=0.1
3#pragma IgorVersion=6.1
4
5//***********************
6// NOV 2015 Vers 0.1
7//
8// Initialization procedures that must be run before anything
9// this is accomplished by placing:
10//
11// Initialize()
12// #include "includes"
13//
14// in the built-in procedure window of the .pxt (template) experiment
15// IGOR recognizes this, and executes Initialize() immediately after
16// compiling all of the included procedures. This is all done as the blank
17// template is opened
18//
19// Choosing initialize from the VSANS menu will do the same, and no harm is done
20// to the experiment by re- initializing. no data or folders are overwritten
21//
22//************************
23
24
25
26// TODO -- need to set up a separate file of "constants" or "globals" where the actual numbers are
27//stored. If there are not a lot, that place could be here. InitFacilityGlobals() is currently in NCNR_Utils.ipf
28
29
30
31
32Proc Initialize_VSANS()
33        V_Initialize()
34End
35
36//this is the main initualization procedure that must be the first thing
37//done when opening a new Data reduction experiment
38//
39//sets up data folders, globals, protocols, and draws the main panel
40Proc V_Initialize()
41
42        Variable curVersion = 0.1
43        Variable oldVersion = NumVarOrDefault("root:VSANS_RED_VERSION",curVersion)
44               
45        if(oldVersion == curVersion)
46                //must just be a new startup with the current version
47                Variable/G root:VSANS_RED_VERSION=0.1
48        endif
49       
50        if(oldVersion < curVersion)
51                String str =    "This experiment was created with version "+num2str(oldVersion)+" of the macros. I'll try to make this work, but please start new work with a current template"
52                DoAlert 0,str
53        endif
54       
55        V_InitFolders()
56        V_InitFakeProtocols()
57        V_InitGlobals()
58        V_InitFacilityGlobals()
59        DoWindow/F Main_VSANS_Panel
60        If(V_flag == 0)
61                //draw panel
62                Main_VSANS_Panel()
63        Endif
64//      ResizeCmdWindow()
65
66// TODO - be sure that NCNR is defined correctly       
67        //unload the NCNR_Package_Loader, if NCNR not defined
68        UnloadNCNR_VSANS_Procedures()
69
70End
71
72//creates all the necessary data folders in the root folder
73//does not overwrite any existing folders of the same name
74//it leaves data in them untouched
75//
76// x-- make sure that I have all of the folders that I need
77//
78Function V_InitFolders()
79       
80        NewDataFolder/O root:Packages
81        NewDataFolder/O root:Packages:NIST
82        NewDataFolder/O root:Packages:NIST:VSANS
83       
84// for the file catalog
85        NewDataFolder/O root:Packages:NIST:VSANS:CatVSHeaderInfo
86// for the globals
87        NewDataFolder/O root:Packages:NIST:VSANS:Globals
88// for the raw nexus data (so I don't need to reload to get a single value)
89        NewDataFolder/O root:Packages:NIST:VSANS:RawVSANS
90
91// folders for the reduction steps             
92        NewDataFolder/O root:Packages:NIST:VSANS:RAW
93        NewDataFolder/O root:Packages:NIST:VSANS:SAM
94        NewDataFolder/O root:Packages:NIST:VSANS:EMP
95        NewDataFolder/O root:Packages:NIST:VSANS:BGD
96        NewDataFolder/O root:Packages:NIST:VSANS:COR
97        NewDataFolder/O root:Packages:NIST:VSANS:DIV
98        NewDataFolder/O root:Packages:NIST:VSANS:MSK
99        NewDataFolder/O root:Packages:NIST:VSANS:ABS
100        NewDataFolder/O root:Packages:NIST:VSANS:CAL
101        NewDataFolder/O root:Packages:NIST:VSANS:STO
102        NewDataFolder/O root:Packages:NIST:VSANS:SUB
103        NewDataFolder/O root:Packages:NIST:VSANS:DRK
104        NewDataFolder/O root:Packages:NIST:VSANS:ADJ
105
106
107// ?? anything else
108
109// for simulation
110//      NewDataFolder/O root:Packages:NIST:VSANS:SAS
111
112
113       
114        Return(0)
115End
116
117
118
119
120//
121//Global folder already exists...
122//adds appropriate globals to the newly created myGlobals folder
123//return data folder to root: before leaving
124//
125//
126Function V_InitGlobals()
127       
128       
129        Variable/G root:Packages:NIST:VSANS:Globals:gIsLogScale = 0
130        String/G root:Packages:NIST:VSANS:Globals:gCurDispType = "RAW"
131       
132        //check platform, so Angstrom can be drawn correctly
133
134        //TODO  -- this is different on Igor 7. Macintosh # has been updated, but Windows has not
135        // use Print char2num("Å") to find the magic number
136        if(cmpstr("Macintosh",IgorInfo(2)) == 0)
137                String/G root:Packages:NIST:VSANS:Globals:gAngstStr = num2char(197)
138                String/G root:Packages:NIST:gAngstStr = num2char(197)
139                Variable/G root:Packages:NIST:VSANS:Globals:gIsMac = 1
140        else
141                //either Windows or Windows NT
142                String/G root:Packages:NIST:VSANS:Globals:gAngstStr = num2char(-59)
143                String/G root:Packages:NIST:gAngstStr = num2char(-59)
144                Variable/G root:Packages:NIST:VSANS:Globals:gIsMac = 0
145                //SetIgorOption to keep some PC's (graphics cards?) from smoothing the 2D image
146                Execute "SetIgorOption WinDraw,forceCOLORONCOLOR=1"
147        endif
148       
149        // TODO x- find the SANS preferences, copy over and update for VSANS
150        // x- these are all in PlotUtilsMacro_v40.ipf as the preferences are set up as common
151        // to all packages. I'm not sure that I want to do this with VSANS, but make the packages
152        // separate entities. I'm seeing little benefit of the crossover, especially now that
153        // Analysis is not mine. So for VSANS, there is a new, separate file: V_VSANS_Preferences.ipf
154
155        //this is critical to initialize now - as it has the y/n flags for the detector correction steps
156        Execute "Initialize_VSANSPreferences()"
157
158       
159        // set the lookup waves for log/lin display of the detector images
160        V_MakeImageLookupTables(10000,0,1)
161
162
163
164        //set flag if Demo Version is detected
165        Variable/G root:Packages:NIST:VSANS:Globals:isDemoVersion = V_isDemo()
166       
167        //set XML globals
168//      String/G root:Packages:NIST:gXMLLoader_Title = ""
169       
170        Return(0)
171End
172
173//
174//num = number of points (10000 seeems to be a good number so far)
175// lo = lower value (between 0 and 1)
176// hi = upper value (between 0 and 1)
177//
178// note that it is currenty NOT OK for lo > hi (!= reversed color scale, right now log(negative) == bad)
179//
180// TODO hi, lo not used properly here, seems to mangle log display now that I'm switching the lo,hi of the ctab
181//
182Function V_MakeImageLookupTables(num,lo,hi)
183        Variable num,lo,hi
184
185                // lookup waves for log and linear display of images
186        // this is used for the main data display. With this, I can use the original
187        // detector data (no copy) and the zeros in the data set are tolerated when displaying
188        // on log scale
189        SetDataFolder root:Packages:NIST:VSANS:Globals
190        Variable val,offset
191       
192        offset = 1/num          //can't use 1/lo if lo == 0
193       
194        Make/O/D/N=(num) logLookupWave,linearLookupWave
195       
196        linearLookupWave = (p+1)/num
197       
198       
199        logLookupWave = log(linearLookupWave)
200        val = logLookupWave[0]
201        logLookupWave += -val + offset
202        val = logLookupWave[num-1]
203        logLookupWave /= val
204       
205        SetDataFolder root:
206       
207        return(0)
208end
209
210//
211// initializes globals that are specific to VSANS
212//
213// there really should be nothing here... all of this should now be in the Nexus data file
214// and not tethered to hard-wired constants.
215//
216// -- what was here was:
217// number of detector pixels
218// pixel size
219// deadtime
220// beamstop "tolerance" to identify Trans files
221// sample aperture offset
222//
223Function V_InitFacilityGlobals()
224
225//      //Detector -specific globals
226//      Variable/G root:myGlobals:gNPixelsX=128
227//      Variable/G root:myGlobals:gNPixelsY=128
228//     
229//      // as of Jan2008, detector pixel sizes are read directly from the file header, so they MUST
230//      // be set correctly in instr.cfg - these values are not used, but declared to avoid errors
231//      Variable/G root:myGlobals:PixelResNG3_ILL = 1.0         //pixel resolution in cm
232//      Variable/G root:myGlobals:PixelResNG5_ILL = 1.0
233//      Variable/G root:myGlobals:PixelResNG7_ILL = 1.0
234//      Variable/G root:myGlobals:PixelResNG3_ORNL = 0.5
235//      Variable/G root:myGlobals:PixelResNG5_ORNL = 0.5
236//      Variable/G root:myGlobals:PixelResNG7_ORNL = 0.5
237//      Variable/G root:myGlobals:PixelResNGB_ORNL = 0.5
238////    Variable/G root:myGlobals:PixelResCGB_ORNL = 0.5                // fiction
239//
240//      Variable/G root:myGlobals:PixelResDefault = 0.5
241//     
242//      Variable/G root:myGlobals:DeadtimeNG3_ILL = 3.0e-6              //deadtime in seconds
243//      Variable/G root:myGlobals:DeadtimeNG5_ILL = 3.0e-6
244//      Variable/G root:myGlobals:DeadtimeNG7_ILL = 3.0e-6
245//      Variable/G root:myGlobals:DeadtimeNGB_ILL = 4.0e-6              // fictional
246//      Variable/G root:myGlobals:DeadtimeNG3_ORNL_VAX = 3.4e-6         //pre - 23-JUL-2009 used VAX
247//      Variable/G root:myGlobals:DeadtimeNG3_ORNL_ICE = 1.5e-6         //post - 23-JUL-2009 used ICE
248//      Variable/G root:myGlobals:DeadtimeNG5_ORNL = 0.6e-6                     //as of 9 MAY 2002
249//      Variable/G root:myGlobals:DeadtimeNG7_ORNL_VAX = 3.4e-6         //pre 25-FEB-2010 used VAX
250//      Variable/G root:myGlobals:DeadtimeNG7_ORNL_ICE = 2.3e-6         //post 25-FEB-2010 used ICE
251//      Variable/G root:myGlobals:DeadtimeNGB_ORNL_ICE = 4.0e-6         //per JGB 16-JAN-2013, best value we have for the oscillating data
252//
253////    Variable/G root:myGlobals:DeadtimeCGB_ORNL_ICE = 1.5e-6         // fiction
254//
255//      Variable/G root:myGlobals:DeadtimeDefault = 3.4e-6
256//
257//      //new 11APR07
258//      Variable/G root:myGlobals:BeamstopXTol = -8                     // (cm) is BS Xpos is -5 cm or less, it's a trans measurement
259//      // sample aperture offset is NOT stored in the VAX header, but it should be
260//      // - when it is, remove the global and write an accessor AND make a place for
261//      // it in the RealsRead
262//      Variable/G root:myGlobals:apOff = 5.0                           // (cm) distance from sample aperture to sample position
263
264End
265
266///////////////////////////////////////////////
267// TODO
268////////////// everything below needs to be re-written for VSANS
269//
270//////////////////////////////////////////////
271
272
273//
274// do I need to make the protocols any longer for VSANS? (yes -- now 12 points)
275// What other options for processing / averaging / saving are needed??
276//  TODO
277// x- likely that I'll want to have #pts to cut from I(q) as input to NSORT within the protocol so that the
278// entire reduction can be automatic
279//
280//
281// x- creates the "base" protocols that should be available, after creating the data folder
282// x- all protocols are kept in the root:Packages:NIST:VSANS:Globals:Protocols folder, created here
283//
284//
285//*****as of 05_2017, protocols are 12 points long, [6] is used for work.drk, [7,8] are for trimmig points, and [9,11] are currently unused
286//
287Function V_InitFakeProtocols()
288       
289        NewDataFolder/O root:Packages:NIST:VSANS:Globals:Protocols
290        Make/O/T $"root:Packages:NIST:VSANS:Globals:Protocols:Base"={"none","none","ask","ask","none","AVTYPE=Circular;SAVE=Yes;NAME=Manual;PLOT=Yes","DRK=none,DRKMODE=0,","","","","",""}
291        Make/O/T $"root:Packages:NIST:VSANS:Globals:Protocols:DoAll"={"ask","ask","ask","ask","ask","AVTYPE=Circular;SAVE=Yes;NAME=Manual;PLOT=Yes","DRK=none,DRKMODE=0,","","","","",""}
292        Make/O/T/N=(kNumProtocolSteps) $"root:Packages:NIST:VSANS:Globals:Protocols:CreateNew"                  //null wave
293        //Initialize waves to store values in
294       
295        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr=""
296        String/G root:Packages:NIST:VSANS:Globals:Protocols:gNewStr=""
297        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr = "AVTYPE=Circular;SAVE=Yes;NAME=Auto;PLOT=Yes;BINTYPE=One;"
298       
299        String/G root:Packages:NIST:VSANS:Globals:Protocols:gBegPtsStr=""
300        String/G root:Packages:NIST:VSANS:Globals:Protocols:gEndPtsStr=""
301       
302        Return(0)
303End
304
305//simple function to resize the comand window to a nice size, no matter what the resolution
306//need to test out on several different monitors and both platforms
307//
308// could easily be incorporated into the initialization routines to ensure that the
309// command window is always visible at startup of the macros. No need for a hook function
310//
311Function ResizeCmdWindow()
312
313        String str=IgorInfo(0),rect="",platform=igorinfo(2)
314        Variable depth,left,top,right,bottom,factor
315       
316        if(cmpstr(platform,"Macintosh")==0)
317                factor=1
318        else
319                factor = 0.6            //fudge factor to get command window on-screen on Windows
320        endif
321        rect = StringByKey("SCREEN1", str  ,":",";")   
322        sscanf rect,"DEPTH=%d,RECT=%d,%d,%d,%d",depth, left,top,right,bottom
323        MoveWindow/C  (left+3)*factor,(bottom-150)*factor,(right-50)*factor,(bottom-10)*factor
324End
325
326// since the NCNR procedures can't be loaded concurrently with the other facility functions,
327// unload this procedure file, and add this to the functions that run at initialization of the
328// experiment
329//
330// TODO - be sure that this unloads correctly
331Function UnloadNCNR_VSANS_Procedures()
332
333#if (exists("NCNR_VSANS")==6)                   //defined in the main #includes file.
334        //do nothing if an NCNR reduction experiment
335#else
336        if(ItemsInList(WinList("NCNR_Package_Loader.ipf", ";","WIN:128")))
337                Execute/P "CloseProc /NAME=\"NCNR_Package_Loader.ipf\""
338                Execute/P "COMPILEPROCEDURES "
339        endif
340#endif
341
342End
343
344//returns 1 if demo version, 0 if full version
345Function V_IsDemo()
346
347        // create small offscreen graph
348        Display/W=(3000,3000,3010,3010)
349        DoWindow/C IsDemoGraph
350
351        // try to save a PICT or bitmap of it to the clipboard
352        SavePICT/Z  as "Clipboard"
353        Variable isDemo= V_Flag != 0    // if error: must be demo
354        DoWindow/K IsDemoGraph
355        return isDemo
356End
357
358// Clean out the RawVSANS folder before saving
359Function BeforeExperimentSaveHook(rN,fileName,path,type,creator,kind)
360        Variable rN,kind
361        String fileName,path,type,creator
362
363        // clean out, so that the file SAVE is not slow due to the large experiment size
364        // TODO -- decide if this is really necessary
365//     
366//      V_CleanOutRawVSANS()
367// present a progress window
368        V_CleanupData_w_Progress(0,1)
369        Printf "Hook cleaned out RawVSANS, experiment saved\r"
370
371End
Note: See TracBrowser for help on using the repository browser.