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

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

Filling in missing "dummy" functions when XML xop is not present.

Added new V_ procedures for the beginning of the reduction steps - initialization, main panel, preferences, and a menu. These are lifted directly from the SANS routines and much still needs to be modified.

File size: 10.6 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//
32/// Search for TODO to clean up the missing pieces
33//
34
35
36
37
38
39Proc Initialize_VSANS()
40        V_Initialize()
41End
42
43//this is the main initualization procedure that must be the first thing
44//done when opening a new Data reduction experiment
45//
46//sets up data folders, globals, protocols, and draws the main panel
47Proc V_Initialize()
48
49        Variable curVersion = 0.1
50        Variable oldVersion = NumVarOrDefault("root:VSANS_RED_VERSION",curVersion)
51               
52        if(oldVersion == curVersion)
53                //must just be a new startup with the current version
54                Variable/G root:VSANS_RED_VERSION=0.1
55        endif
56       
57        if(oldVersion < curVersion)
58                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"
59                DoAlert 0,str
60        endif
61       
62        V_InitFolders()
63        V_InitFakeProtocols()
64        V_InitGlobals()
65        V_InitFacilityGlobals()
66        DoWindow/F Main_VSANS_Panel
67        If(V_flag == 0)
68                //draw panel
69                Main_VSANS_Panel()
70        Endif
71//      ResizeCmdWindow()
72
73// TODO - be sure that NCNR is defined correctly       
74        //unload the NCNR_Package_Loader, if NCNR not defined
75        UnloadNCNR_VSANS_Procedures()
76
77End
78
79//creates all the necessary data folders in the root folder
80//does not overwrite any existing folders of the same name
81//it leaves data in them untouched
82//
83// TODO -- make sure that I have all of the folders that I need
84//
85Function V_InitFolders()
86       
87        NewDataFolder/O root:Packages
88        NewDataFolder/O root:Packages:NIST
89        NewDataFolder/O root:Packages:NIST:VSANS
90       
91// for the file catalog
92        NewDataFolder/O root:Packages:NIST:VSANS:CatVSHeaderInfo
93// for the globals
94        NewDataFolder/O root:Packages:NIST:VSANS:Globals
95// for the raw nexus data (so I don't need to reload to get a single value)
96        NewDataFolder/O root:Packages:NIST:VSANS:RawVSANS
97
98// folders for the reduction steps             
99        NewDataFolder/O root:Packages:NIST:VSANS:RAW
100        NewDataFolder/O root:Packages:NIST:VSANS:SAM
101        NewDataFolder/O root:Packages:NIST:VSANS:EMP
102        NewDataFolder/O root:Packages:NIST:VSANS:BGD
103        NewDataFolder/O root:Packages:NIST:VSANS:COR
104        NewDataFolder/O root:Packages:NIST:VSANS:DIV
105        NewDataFolder/O root:Packages:NIST:VSANS:MSK
106        NewDataFolder/O root:Packages:NIST:VSANS:ABS
107        NewDataFolder/O root:Packages:NIST:VSANS:CAL
108        NewDataFolder/O root:Packages:NIST:VSANS:STO
109        NewDataFolder/O root:Packages:NIST:VSANS:SUB
110        NewDataFolder/O root:Packages:NIST:VSANS:DRK
111
112
113// ?? anything else
114
115// for simulation
116//      NewDataFolder/O root:Packages:NIST:VSANS:SAS
117
118
119       
120        Return(0)
121End
122
123
124
125
126//
127//Global folder already exists...
128//adds appropriate globals to the newly created myGlobals folder
129//return data folder to root: before leaving
130//
131//
132Function V_InitGlobals()
133       
134        Variable/G root:Packages:NIST:VSANS:Globals:gIsLogScale = 0
135        String/G root:Packages:NIST:VSANS:Globals:gDataDisplayType = "RAW"
136       
137        //check platform, so Angstrom can be drawn correctly
138
139        //TODO  - this is different on Igor 7
140        if(cmpstr("Macintosh",IgorInfo(2)) == 0)
141                String/G root:Packages:NIST:VSANS:Globals:gAngstStr = num2char(-127)
142                Variable/G root:Packages:NIST:VSANS:Globals:gIsMac = 1
143        else
144                //either Windows or Windows NT
145                String/G root:Packages:NIST:VSANS:Globals:gAngstStr = num2char(-59)
146                Variable/G root:Packages:NIST:VSANS:Globals:gIsMac = 0
147                //SetIgorOption to keep some PC's (graphics cards?) from smoothing the 2D image
148                Execute "SetIgorOption WinDraw,forceCOLORONCOLOR=1"
149        endif
150       
151        // TODO -- find the SANS preferences, copy over and update for VSANS
152        // -- these are all in PlotUtilsMacro_v40.ipf as the preferences are set up as common
153        // to all packages. I'm not sure that I want to do this with VSANS, but make the packages
154        // separate entities. I'm seeing little benefit of the crossover, especially now that
155        // Analysis is not mine. So for VSANS, there is a new, separate file: V_VSANS_Preferences.ipf
156
157        Execute "Initialize_VSANSPreferences()"
158
159       
160
161
162        //set flag if Demo Version is detected
163        Variable/G root:Packages:NIST:VSANS:Globals:isDemoVersion = V_isDemo()
164       
165        //set XML globals
166//      String/G root:Packages:NIST:gXMLLoader_Title = ""
167       
168        Return(0)
169End
170
171
172//
173// initializes globals that are specific to VSANS
174//
175// there really should be nothing here... all of this should now be in the Nexus data file
176// and not tethered to hard-wired constants.
177//
178// -- what was here was:
179// number of detector pixels
180// pixel size
181// deadtime
182// beamstop "tolerance" to identify Trans files
183// sample aperture offset
184//
185Function V_InitFacilityGlobals()
186
187//      //Detector -specific globals
188//      Variable/G root:myGlobals:gNPixelsX=128
189//      Variable/G root:myGlobals:gNPixelsY=128
190//     
191//      // as of Jan2008, detector pixel sizes are read directly from the file header, so they MUST
192//      // be set correctly in instr.cfg - these values are not used, but declared to avoid errors
193//      Variable/G root:myGlobals:PixelResNG3_ILL = 1.0         //pixel resolution in cm
194//      Variable/G root:myGlobals:PixelResNG5_ILL = 1.0
195//      Variable/G root:myGlobals:PixelResNG7_ILL = 1.0
196//      Variable/G root:myGlobals:PixelResNG3_ORNL = 0.5
197//      Variable/G root:myGlobals:PixelResNG5_ORNL = 0.5
198//      Variable/G root:myGlobals:PixelResNG7_ORNL = 0.5
199//      Variable/G root:myGlobals:PixelResNGB_ORNL = 0.5
200////    Variable/G root:myGlobals:PixelResCGB_ORNL = 0.5                // fiction
201//
202//      Variable/G root:myGlobals:PixelResDefault = 0.5
203//     
204//      Variable/G root:myGlobals:DeadtimeNG3_ILL = 3.0e-6              //deadtime in seconds
205//      Variable/G root:myGlobals:DeadtimeNG5_ILL = 3.0e-6
206//      Variable/G root:myGlobals:DeadtimeNG7_ILL = 3.0e-6
207//      Variable/G root:myGlobals:DeadtimeNGB_ILL = 4.0e-6              // fictional
208//      Variable/G root:myGlobals:DeadtimeNG3_ORNL_VAX = 3.4e-6         //pre - 23-JUL-2009 used VAX
209//      Variable/G root:myGlobals:DeadtimeNG3_ORNL_ICE = 1.5e-6         //post - 23-JUL-2009 used ICE
210//      Variable/G root:myGlobals:DeadtimeNG5_ORNL = 0.6e-6                     //as of 9 MAY 2002
211//      Variable/G root:myGlobals:DeadtimeNG7_ORNL_VAX = 3.4e-6         //pre 25-FEB-2010 used VAX
212//      Variable/G root:myGlobals:DeadtimeNG7_ORNL_ICE = 2.3e-6         //post 25-FEB-2010 used ICE
213//      Variable/G root:myGlobals:DeadtimeNGB_ORNL_ICE = 4.0e-6         //per JGB 16-JAN-2013, best value we have for the oscillating data
214//
215////    Variable/G root:myGlobals:DeadtimeCGB_ORNL_ICE = 1.5e-6         // fiction
216//
217//      Variable/G root:myGlobals:DeadtimeDefault = 3.4e-6
218//
219//      //new 11APR07
220//      Variable/G root:myGlobals:BeamstopXTol = -8                     // (cm) is BS Xpos is -5 cm or less, it's a trans measurement
221//      // sample aperture offset is NOT stored in the VAX header, but it should be
222//      // - when it is, remove the global and write an accessor AND make a place for
223//      // it in the RealsRead
224//      Variable/G root:myGlobals:apOff = 5.0                           // (cm) distance from sample aperture to sample position
225
226End
227
228///////////////////////////////////////////////
229//
230////////////// everything below needs to be re-written for VSANS
231//
232//////////////////////////////////////////////
233
234
235// TODO
236// do I need to make the protocols any longer for VSANS?
237// What other options for processing / averaging / saving are needed??
238// - TODO
239// -- likely that I'll want to have #pts to cut from I(q) as input to NSORT within the protocol so that the
240// entire reduction can be automatic
241//
242//
243// -- creates the "base" protocols that should be available, after creating the data folder
244// -- all protocols are kept in the root:Packages:NIST:VSANS:Globals:Protocols folder, created here
245//
246Function V_InitFakeProtocols()
247       
248        //*****as of 0901, protocols are 8 points long, [6] is used for work.drk, [7] is unused
249        NewDataFolder/O root:Packages:NIST:VSANS:Globals:Protocols
250        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,",""}
251        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,",""}
252        Make/O/T/N=8 $"root:Packages:NIST:VSANS:Globals:Protocols:CreateNew"                    //null wave
253        //Initialize waves to store values in
254       
255        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr=""
256        String/G root:Packages:NIST:VSANS:Globals:Protocols:gNewStr=""
257        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr = "AVTYPE=Circular;SAVE=Yes;NAME=Auto;PLOT=Yes;"
258       
259        Return(0)
260End
261
262//simple function to resize the comand window to a nice size, no matter what the resolution
263//need to test out on several different monitors and both platforms
264//
265// could easily be incorporated into the initialization routines to ensure that the
266// command window is always visible at startup of the macros. No need for a hook function
267//
268Function ResizeCmdWindow()
269
270        String str=IgorInfo(0),rect="",platform=igorinfo(2)
271        Variable depth,left,top,right,bottom,factor
272       
273        if(cmpstr(platform,"Macintosh")==0)
274                factor=1
275        else
276                factor = 0.6            //fudge factor to get command window on-screen on Windows
277        endif
278        rect = StringByKey("SCREEN1", str  ,":",";")   
279        sscanf rect,"DEPTH=%d,RECT=%d,%d,%d,%d",depth, left,top,right,bottom
280        MoveWindow/C  (left+3)*factor,(bottom-150)*factor,(right-50)*factor,(bottom-10)*factor
281End
282
283// since the NCNR procedures can't be loaded concurrently with the other facility functions,
284// unload this procedure file, and add this to the functions that run at initialization of the
285// experiment
286//
287// TODO - be sure that this unloads correctly
288Function UnloadNCNR_VSANS_Procedures()
289
290#if (exists("NCNR_VSANS")==6)                   //defined in the main #includes file.
291        //do nothing if an NCNR reduction experiment
292#else
293        if(ItemsInList(WinList("NCNR_Package_Loader.ipf", ";","WIN:128")))
294                Execute/P "CloseProc /NAME=\"NCNR_Package_Loader.ipf\""
295                Execute/P "COMPILEPROCEDURES "
296        endif
297#endif
298
299End
300
301//returns 1 if demo version, 0 if full version
302Function V_IsDemo()
303
304        // create small offscreen graph
305        Display/W=(3000,3000,3010,3010)
306        DoWindow/C IsDemoGraph
307
308        // try to save a PICT or bitmap of it to the clipboard
309        SavePICT/Z  as "Clipboard"
310        Variable isDemo= V_Flag != 0    // if error: must be demo
311        DoWindow/K IsDemoGraph
312        return isDemo
313End
Note: See TracBrowser for help on using the repository browser.