source: sans/Dev/branches/quokka_fix/NCNR_User_Procedures/Reduction/SANS/QKK_Initialize.ipf @ 1233

Last change on this file since 1233 was 1233, checked in by geishm, 3 years ago

Removed redundant call to SetIgorOption? that is missing in latest IGOR 8 release.

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