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

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

Updated version of HFIR_DataReadWrite.ipf from Jae Hie.

Updated the initialization of the templates from other facilities to remove the NCNR_Package_Loader.ipf since they are by definition incompatible.

Forward/Back? incrementing of the run number (as for the 2D display) has been moved to the Facility_Utils.ipf for all facilities and for the template.

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