source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Initialize.ipf @ 1023

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

many additions.

Moved unused igor/nexus testing files to Vx_ prefix since they're garbage. Pulled out the useful bits for mask and div R/W and moved those to theire appropriate procedures.

Testing the simple correction of data, only tested basic subtraction. All of it still needs to be verified since I don't have any real header numbers and units yet.

Adjusted the columns on the file catalog to be more appropriate, and added a hook to allow loading of raw data files directly from the table and a popup contextual menu. May add more functionality to it later.

Corrected how the 1D data is plotted so that it correctly uses the binning type. I(q) save now also uses the binning as specified.

File size: 6.8 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.2
3#pragma IgorVersion=6.1
4
5//***********************
6// 091901 Vers 1.2
7//
8// Initialization procedures that must be run before any analysis is started
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 SANS 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//this is the main initualization procedure that must be the first thing
25//done when opening a new Data reduction experiment
26//
27//sets up data folders, globals, protocols, and draws the main panel
28Proc Initialize()
29
30        Variable curVersion = 5.2
31        Variable oldVersion = NumVarOrDefault("root:SANS_RED_VERSION",curVersion)
32       
33        //check for really old versions
34        if(itemsinlist(WinList("Includes.ipf", ";","INCLUDE:6"),";") != 0)
35                //must be opening a v4.2 or earlier template
36                oldVersion = 4.2
37        endif
38       
39        if(itemsinlist(WinList("Includes_v510.ipf", ";","INCLUDE:6"),";") != 0)
40                oldVersion = 5.10
41        endif
42        if(itemsinlist(WinList("Includes_v500.ipf", ";","INCLUDE:6"),";") != 0)
43                oldVersion = 5.00
44        endif
45       
46        if(oldVersion == curVersion)
47                //must just be a new startup with the current version
48                Variable/G root:SANS_RED_VERSION=5.20
49        endif
50       
51        if(oldVersion < curVersion)
52                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"
53                DoAlert 0,str
54        endif
55       
56        InitFolders()
57        InitFakeProtocols()
58        InitGlobals()   
59        InitFacilityGlobals()
60        DoWindow/F Main_Panel
61        If(V_flag == 0)
62                //draw panel
63                Main_Panel()
64        Endif
65//      ResizeCmdWindow()
66       
67        //unload the NCNR_Package_Loader, if NCNR not defined
68        UnloadNCNR_Igor_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
75Function InitFolders()
76       
77        NewDataFolder/O root:Packages
78        NewDataFolder/O root:Packages:NIST
79       
80        NewDataFolder/O root:myGlobals
81        NewDataFolder/O root:myGlobals:CatVSHeaderInfo
82        NewDataFolder/O root:Packages:NIST:RAW
83        NewDataFolder/O root:Packages:NIST:SAM
84        NewDataFolder/O root:Packages:NIST:EMP
85        NewDataFolder/O root:Packages:NIST:BGD
86        NewDataFolder/O root:Packages:NIST:COR
87        NewDataFolder/O root:Packages:NIST:DIV
88        NewDataFolder/O root:Packages:NIST:MSK
89        NewDataFolder/O root:Packages:NIST:ABS
90        NewDataFolder/O root:Packages:NIST:CAL
91        NewDataFolder/O root:Packages:NIST:STO
92        NewDataFolder/O root:Packages:NIST:SUB
93        NewDataFolder/O root:Packages:NIST:DRK
94
95        NewDataFolder/O root:Packages:NIST:SAS
96
97
98       
99        Return(0)
100End
101
102//Global folder already exists...
103//adds appropriate globals to the newly created myGlobals folder
104//return data folder to root: before leaving
105//
106// global parameters used for detector constants are facility specific
107// and have been moved
108//
109Function InitGlobals()
110       
111        Variable/G root:myGlobals:gIsLogScale = 0
112        String/G root:myGlobals:gDataDisplayType = "RAW"
113       
114        //check platform, so Angstrom can be drawn correctly
115       
116        if(cmpstr("Macintosh",IgorInfo(2)) == 0)
117//              String/G root:Packages:NIST:gAngstStr = num2char(-127)
118                String/G root:Packages:NIST:gAngstStr = num2char(197)
119                Variable/G root:myGlobals:gIsMac = 1
120        else
121                //either Windows or Windows NT
122                String/G root:Packages:NIST:gAngstStr = num2char(-59)
123                Variable/G root:myGlobals:gIsMac = 0
124                //SetIgorOption to keep some PC's (graphics cards?) from smoothing the 2D image
125                Execute "SetIgorOption WinDraw,forceCOLORONCOLOR=1"
126        endif
127       
128        //global to set log scale as the default for display of RAW data
129        //these can be set using the Misc->Preferences panel
130        //initializes preferences. this includes XML y/n, and SANS Reduction items.
131        // if they already exist, they won't be overwritten
132        Execute "Initialize_Preferences()"     
133
134       
135
136
137        //set flag if Demo Version is detected
138        Variable/G root:myGlobals:isDemoVersion = isDemo()
139       
140        //set XML globals
141        String/G root:Packages:NIST:gXMLLoader_Title = ""
142       
143        Return(0)
144End
145
146//creates the "base" protocols that should be available, after creating the data folder
147//
148//all protocols are kept in the root:myGlobals:Protocols folder, created here
149//
150Function InitFakeProtocols()
151       
152        //*****as of 0901, protocols are 8 points long, [6] is used for work.drk, [7] is unused
153        NewDataFolder/O root:myGlobals:Protocols
154        Make/O/T $"root:myGlobals:Protocols:Base"={"none","none","ask","ask","none","AVTYPE=Circular;SAVE=Yes;NAME=Manual;PLOT=Yes","DRK=none,DRKMODE=0,",""}
155        Make/O/T $"root:myGlobals:Protocols:DoAll"={"ask","ask","ask","ask","ask","AVTYPE=Circular;SAVE=Yes;NAME=Manual;PLOT=Yes","DRK=none,DRKMODE=0,",""}
156        Make/O/T/N=8 $"root:myGlobals:Protocols:CreateNew"                      //null wave
157        //Initialize waves to store values in
158       
159        String/G root:myGlobals:Protocols:gProtoStr=""
160        String/G root:myGlobals:Protocols:gNewStr=""
161        String/G root:myGlobals:Protocols:gAvgInfoStr = "AVTYPE=Circular;SAVE=Yes;NAME=Auto;PLOT=Yes;"
162       
163        Return(0)
164End
165
166//simple function to resize the comand window to a nice size, no matter what the resolution
167//need to test out on several different monitors and both platforms
168//
169// could easily be incorporated into the initialization routines to ensure that the
170// command window is always visible at startup of the macros. No need for a hook function
171//
172Function ResizeCmdWindow()
173
174        String str=IgorInfo(0),rect="",platform=igorinfo(2)
175        Variable depth,left,top,right,bottom,factor
176       
177        if(cmpstr(platform,"Macintosh")==0)
178                factor=1
179        else
180                factor = 0.6            //fudge factor to get command window on-screen on Windows
181        endif
182        rect = StringByKey("SCREEN1", str  ,":",";")   
183        sscanf rect,"DEPTH=%d,RECT=%d,%d,%d,%d",depth, left,top,right,bottom
184        MoveWindow/C  (left+3)*factor,(bottom-150)*factor,(right-50)*factor,(bottom-10)*factor
185End
186
187// since the NCNR procedures can't be loaded concurrently with the other facility functions,
188// unload this procedure file, and add this to the functions that run at initialization of the
189// experiment
190Function UnloadNCNR_Igor_Procedures()
191
192#if (exists("NCNR")==6)                 //defined in the main #includes file.
193        //do nothing if an NCNR reduction experiment
194#else
195        if(ItemsInList(WinList("NCNR_Package_Loader.ipf", ";","WIN:128")))
196                Execute/P "CloseProc /NAME=\"NCNR_Package_Loader.ipf\""
197                Execute/P "COMPILEPROCEDURES "
198        endif
199#endif
200
201End
202
203//returns 1 if demo version, 0 if full version
204Function IsDemo()
205
206        // create small offscreen graph
207        Display/W=(3000,3000,3010,3010)
208        DoWindow/C IsDemoGraph
209
210        // try to save a PICT or bitmap of it to the clipboard
211        SavePICT/Z  as "Clipboard"
212        Variable isDemo= V_Flag != 0    // if error: must be demo
213        DoWindow/K IsDemoGraph
214        return isDemo
215End
Note: See TracBrowser for help on using the repository browser.