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

Last change on this file was 1147, checked in by srkline, 4 years ago

bug fix for Igor 8 - removing the setIgorOption forceCOLORONCOLOR for windows graphics. No longer needed in Igor 8, and generates an error. removed this line in the initialization step in all packages.

bug fix for the defining of a mask for sector averaging in VSANS. beam center in [cm] was incorrectly converted to [pixels]. No other calculations were affected.

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