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

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

Change (1):
In preparation for release, updated pragma IgorVersion?=6.1 in all procedures

Change (2):
As a side benefit of requiring 6.1, we can use the MultiThread? keyword to thread any model function we like. The speed benefit is only noticeable on functions that require at least one integration and at least 100 points (resolution smearing is NOT threaded, too many threadSafe issues, too little benefit). I have chosen to use the MultiThread? only on the XOP assignment. In the Igor code there are too many functions that are not explicitly declared threadsafe, making for a mess.

File size: 5.8 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()
47End
48
49//creates all the necessary data folders in the root folder
50//does not overwrite any existing folders of the same name
51//it leaves data in them untouched
52Function InitFolders()
53       
54        NewDataFolder/O root:Packages
55        NewDataFolder/O root:Packages:NIST
56       
57        NewDataFolder/O root:myGlobals
58        NewDataFolder/O root:myGlobals:CatVSHeaderInfo
59        NewDataFolder/O root:Packages:NIST:RAW
60        NewDataFolder/O root:Packages:NIST:SAM
61        NewDataFolder/O root:Packages:NIST:EMP
62        NewDataFolder/O root:Packages:NIST:BGD
63        NewDataFolder/O root:Packages:NIST:COR
64        NewDataFolder/O root:Packages:NIST:DIV
65        NewDataFolder/O root:Packages:NIST:MSK
66        NewDataFolder/O root:Packages:NIST:ABS
67        NewDataFolder/O root:Packages:NIST:CAL
68        NewDataFolder/O root:Packages:NIST:STO
69        NewDataFolder/O root:Packages:NIST:SUB
70        NewDataFolder/O root:Packages:NIST:DRK
71       
72
73       
74        Return(0)
75End
76
77//Global folder already exists...
78//adds appropriate globals to the newly created myGlobals folder
79//return data folder to root: before leaving
80//
81// global parameters used for detector constants are facility specific
82// and have been moved
83//
84Function InitGlobals()
85       
86        Variable/G root:myGlobals:gIsLogScale = 0
87        String/G root:myGlobals:gDataDisplayType = "RAW"
88       
89        //check platform, so Angstrom can be drawn correctly
90       
91        if(cmpstr("Macintosh",IgorInfo(2)) == 0)
92                String/G root:myGlobals:gAngstStr = num2char(-127)
93                Variable/G root:myGlobals:gIsMac = 1
94        else
95                //either Windows or Windows NT
96                String/G root:myGlobals:gAngstStr = num2char(-59)
97                Variable/G root:myGlobals:gIsMac = 0
98                //SetIgorOption to keep some PC's (graphics cards?) from smoothing the 2D image
99                Execute "SetIgorOption WinDraw,forceCOLORONCOLOR=1"
100        endif
101       
102        //global to set log scale as the default for display of RAW data
103        //these can be set using the Misc->Preferences panel
104        Variable/G root:myGlobals:gLogScalingAsDefault=1
105        Variable/G root:myGlobals:gAllowDRK=0                   //don't show DRK as default
106        Variable/G root:myGlobals:gDoTransCheck=1
107        Variable/G root:myGlobals:gBinWidth=1
108        Variable/G root:myGlobals:gNPhiSteps=72
109       
110        // flags to turn detector corrections on/off for testing (you should leave these ON)
111        Variable/G root:myGlobals:gDoDetectorEffCorr = 1
112        Variable/G root:myGlobals:gDoTransmissionCorr = 1
113
114        //set flag if Demo Version is detected
115        Variable/G root:myGlobals:isDemoVersion = isDemo()
116       
117        //set XML globals
118        String/G root:Packages:NIST:gXMLLoader_Title = ""
119
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
166//returns 1 if demo version, 0 if full version
167Function IsDemo()
168
169        // create small offscreen graph
170        Display/W=(3000,3000,3010,3010)
171        DoWindow/C IsDemoGraph
172
173        // try to save a PICT or bitmap of it to the clipboard
174        SavePICT/Z  as "Clipboard"
175        Variable isDemo= V_Flag != 0    // if error: must be demo
176        DoWindow/K IsDemoGraph
177        return isDemo
178End
Note: See TracBrowser for help on using the repository browser.