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

Last change on this file since 693 was 693, checked in by srkline, 13 years ago

Corrected the identification of HFIR trans files

Added new includes for analysis and usans, with higher version numbers. the old ones now simply point to the new one. this provides a mechanism for identifying experiments that were generated and saved with an older version of the macros - the old include file will be present. All three packages now display an alert if the experiment was generated from asn old version of the macros.

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