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

Last change on this file since 890 was 871, checked in by srkline, 10 years ago

A number of changes to provide the first - alpha version of event mode processing. Works for oscillatory mode data, and a continuous stream. Short on documentation, needs lots of testing.

File size: 6.7 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                Variable/G root:myGlobals:gIsMac = 1
119        else
120                //either Windows or Windows NT
121                String/G root:Packages:NIST:gAngstStr = num2char(-59)
122                Variable/G root:myGlobals:gIsMac = 0
123                //SetIgorOption to keep some PC's (graphics cards?) from smoothing the 2D image
124                Execute "SetIgorOption WinDraw,forceCOLORONCOLOR=1"
125        endif
126       
127        //global to set log scale as the default for display of RAW data
128        //these can be set using the Misc->Preferences panel
129        //initializes preferences. this includes XML y/n, and SANS Reduction items.
130        // if they already exist, they won't be overwritten
131        Execute "Initialize_Preferences()"     
132
133       
134
135
136        //set flag if Demo Version is detected
137        Variable/G root:myGlobals:isDemoVersion = isDemo()
138       
139        //set XML globals
140        String/G root:Packages:NIST:gXMLLoader_Title = ""
141       
142        Return(0)
143End
144
145//creates the "base" protocols that should be available, after creating the data folder
146//
147//all protocols are kept in the root:myGlobals:Protocols folder, created here
148//
149Function InitFakeProtocols()
150       
151        //*****as of 0901, protocols are 8 points long, [6] is used for work.drk, [7] is unused
152        NewDataFolder/O root:myGlobals:Protocols
153        Make/O/T $"root:myGlobals:Protocols:Base"={"none","none","ask","ask","none","AVTYPE=Circular;SAVE=Yes;NAME=Manual;PLOT=Yes","DRK=none,DRKMODE=0,",""}
154        Make/O/T $"root:myGlobals:Protocols:DoAll"={"ask","ask","ask","ask","ask","AVTYPE=Circular;SAVE=Yes;NAME=Manual;PLOT=Yes","DRK=none,DRKMODE=0,",""}
155        Make/O/T/N=8 $"root:myGlobals:Protocols:CreateNew"                      //null wave
156        //Initialize waves to store values in
157       
158        String/G root:myGlobals:Protocols:gProtoStr=""
159        String/G root:myGlobals:Protocols:gNewStr=""
160        String/G root:myGlobals:Protocols:gAvgInfoStr = "AVTYPE=Circular;SAVE=Yes;NAME=Auto;PLOT=Yes;"
161       
162        Return(0)
163End
164
165//simple function to resize the comand window to a nice size, no matter what the resolution
166//need to test out on several different monitors and both platforms
167//
168// could easily be incorporated into the initialization routines to ensure that the
169// command window is always visible at startup of the macros. No need for a hook function
170//
171Function ResizeCmdWindow()
172
173        String str=IgorInfo(0),rect="",platform=igorinfo(2)
174        Variable depth,left,top,right,bottom,factor
175       
176        if(cmpstr(platform,"Macintosh")==0)
177                factor=1
178        else
179                factor = 0.6            //fudge factor to get command window on-screen on Windows
180        endif
181        rect = StringByKey("SCREEN1", str  ,":",";")   
182        sscanf rect,"DEPTH=%d,RECT=%d,%d,%d,%d",depth, left,top,right,bottom
183        MoveWindow/C  (left+3)*factor,(bottom-150)*factor,(right-50)*factor,(bottom-10)*factor
184End
185
186// since the NCNR procedures can't be loaded concurrently with the other facility functions,
187// unload this procedure file, and add this to the functions that run at initialization of the
188// experiment
189Function UnloadNCNR_Igor_Procedures()
190
191#if (exists("NCNR")==6)                 //defined in the main #includes file.
192        //do nothing if an NCNR reduction experiment
193#else
194        if(ItemsInList(WinList("NCNR_Package_Loader.ipf", ";","WIN:128")))
195                Execute/P "CloseProc /NAME=\"NCNR_Package_Loader.ipf\""
196                Execute/P "COMPILEPROCEDURES "
197        endif
198#endif
199
200End
201
202//returns 1 if demo version, 0 if full version
203Function IsDemo()
204
205        // create small offscreen graph
206        Display/W=(3000,3000,3010,3010)
207        DoWindow/C IsDemoGraph
208
209        // try to save a PICT or bitmap of it to the clipboard
210        SavePICT/Z  as "Clipboard"
211        Variable isDemo= V_Flag != 0    // if error: must be demo
212        DoWindow/K IsDemoGraph
213        return isDemo
214End
Note: See TracBrowser for help on using the repository browser.