source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/QKK_DesmearingUtils.ipf @ 1215

Last change on this file since 1215 was 1215, checked in by krzywon, 3 years ago

Merge quokka_update changes into trunk.

File size: 7.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma Version=2.20
3#pragma IgorVersion=6.1
4
5
6// A collection of function needed to implement the desmearing algorithm in the Quokka package
7
8// initializes the folders and globals for use with the USANS_Panel
9// waves for the listboxes must exist before the panel is drawn
10// "dummy" values for the COR_Graph are set here
11// instrumental constants are set here as well
12//
13Proc Init_MainUSANS()
14        NewDataFolder/O root:Packages
15        NewDataFolder/O root:Packages:NIST
16        NewDataFolder/O root:Packages:NIST:USANS
17        NewDataFolder/O root:Packages:NIST:USANS:Globals
18        NewDataFolder/O/S root:Packages:NIST:USANS:Globals:MainPanel
19       
20       
21        if(cmpstr("Macintosh",IgorInfo(2)) == 0)
22                String/G root:Packages:NIST:gAngstStr = num2char(-127)
23//              Variable/G root:myGlobals:gIsMac = 1
24        else
25                //either Windows or Windows NT
26                String/G root:Packages:NIST:gAngstStr = num2char(-59)
27//              Variable/G root:myGlobals:gIsMac = 0
28                //SetIgorOption to keep some PC's (graphics cards?) from smoothing the 2D image
29                Execute "SetIgorOption WinDraw,forceCOLORONCOLOR=1"
30        endif
31       
32        String/G root:Packages:NIST:USANS:Globals:gUSANSFolder  = "root:Packages:NIST:USANS"
33        String USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
34        //NB This is also hardcoded a bit further down - search for "WHY WHY WHY" AJJ Sept 08
35       
36
37        Make/O/T/N=1 fileWave,samWave,empWave,curWave //Added curWave Sept 06 A. Jackson
38        fileWave=""
39        samWave=""
40        empWave=""
41        curWave="" //Added Sept 06 A. Jackson
42        //Wave for handling Current Data AJJ Sept 06
43        Make/O/N=1 SAMisCurrent,EMPisCurrent
44        SAMisCurrent = 0
45        EMPisCurrent = 0
46        Make/O/T/N=5 statusWave=""
47        Make/O/B/U/N=1 selFileW
48        Make/O/B/U/N=1 cselFileW
49        //for the graph control bar
50        Variable/G gTransWide = 1
51        Variable/G gTransRock = 1
52        Variable/G gEmpCts = 0.76                       //default values as of 15 DEC 05 J. Barker
53        Variable/G gBkgCts = 0.62                       //default values as of 15 DEC 05 J. Barker
54        Variable/G gThick = 0.1
55        Variable/G gTypeCheck=1
56        Variable/G gTransRatio=1
57        //Text filter for data files AJJ Sept 06
58        String/G FilterStr
59        Variable/G gUseCurrentData = 0
60       
61        SetDataFolder root:
62       
63        NewDataFolder/O $(USANSFolder+":RAW")
64        NewDataFolder/O $(USANSFolder+":SAM")
65        NewDataFolder/O $(USANSFolder+":COR")
66        NewDataFolder/O $(USANSFolder+":EMP")
67        NewDataFolder/O $(USANSFolder+":BKG")
68        NewDataFolder/O $(USANSFolder+":SWAP")
69        NewDataFolder/O $(USANSFolder+":Graph")
70       
71        //dummy waves for bkg and emp levels
72        Make/O $(USANSFolder+":EMP:empLevel"),$(USANSFolder+":BKG:bkgLevel")
73        //WHY WHY WHY????? - because dependencies can only involve globals. No locals allowed, since the dependency
74        // must remain in existence after the function is finished
75        //Explicit dependency
76        root:Packages:NIST:USANS:EMP:empLevel := root:Packages:NIST:USANS:Globals:MainPanel:gEmpCts //dependency to connect to SetVariable in panel
77        root:Packages:NIST:USANS:BKG:bkgLevel := root:Packages:NIST:USANS:Globals:MainPanel:gBkgCts
78
79// initializes facility specific constants to define the instrument     
80        Init_USANS_Facility()   
81
82        //initializes preferences. this includes XML y/n, and SANS Reduction items.
83        // if they already exist, they won't be overwritten
84       
85        Execute "Initialize_Preferences()"     
86       
87End
88
89//facility-specific constants
90Function Init_USANS_Facility()
91
92        //INSTRUMENTAL CONSTANTS
93        Variable/G      root:Packages:NIST:USANS:Globals:MainPanel:gTheta_H = 3.9e-6            //Darwin FWHM   (pre- NOV 2004)
94        Variable/G      root:Packages:NIST:USANS:Globals:MainPanel:gTheta_V = 0.014             //Vertical divergence   (pre- NOV 2004)
95        //Variable/G  root:Globals:MainPanel:gDomega = 2.7e-7           //Solid angle of detector (pre- NOV 2004)
96        Variable/G      root:Packages:NIST:USANS:Globals:MainPanel:gDomega = 7.1e-7             //Solid angle of detector (NOV 2004)
97        Variable/G      root:Packages:NIST:USANS:Globals:MainPanel:gDefaultMCR= 1e6             //factor for normalization
98       
99        //Variable/G  root:Globals:MainPanel:gDQv = 0.037               //divergence, in terms of Q (1/A) (pre- NOV 2004)
100        Variable/G      root:Packages:NIST:USANS:Globals:MainPanel:gDQv = 0.117         //divergence, in terms of Q (1/A)  (NOV 2004)
101
102        String/G root:Packages:NIST:gXMLLoader_Title=""
103       
104        //November 2010 - deadtime corrections -- see USANS_DetectorDeadtime() below
105        //Only used in BT5_Loader.ipf and dependent on date, so defined there on each file load.
106       
107       
108        // to convert from angle (in degrees) to Q (in 1/Angstrom)
109        Variable/G root:Packages:NIST:USANS:Globals:MainPanel:deg2QConv=5.55e-5         //JGB -- 2/24/01
110       
111        // extension string for the raw data files
112        // -- not that the extension as specified here starts with "."
113        String/G        root:Packages:NIST:USANS:Globals:MainPanel:gUExt = ".bt5"
114       
115       
116       
117        return(0)
118end
119
120Function WriteXMLUSANSDesmeared(fullpath,lo,hi,dialog)
121        String fullpath
122        Variable lo,hi,dialog           //=1 will present dialog for name
123       
124        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder       
125       
126        Struct NISTXMLfile nf
127       
128        String termStr="\r\n"
129        String destStr = USANSFolder+":DSM:"
130        String formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr
131       
132        Variable refNum,integer,realval
133       
134        //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error****
135        WAVE Q_dsm =$(destStr + "Q_dsm")
136        WAVE I_dsm=$(destStr + "I_dsm")
137        WAVE S_dsm=$(destStr + "S_dsm")
138       
139        //check each wave
140        If(!(WaveExists(Q_dsm)))
141                Abort "Q_dsm DNExist in WriteUSANSDesmeared()"
142        Endif
143        If(!(WaveExists(I_dsm)))
144                Abort "I_dsm DNExist in WriteUSANSDesmeared()"
145        Endif
146        If(!(WaveExists(S_dsm)))
147                Abort "S_dsm DNExist in WriteUSANSDesmeared()"
148        Endif
149       
150        // 06 FEB 06 SRK
151        // make dummy waves to hold the "fake" resolution, and write it as the last 3 columns
152        //
153        Duplicate/O Q_dsm,res1,res2,res3
154        res3 = 1                // "fake" beamstop shadowing
155        res1 /= 100             //make the sigmaQ so small that there is no smearing
156       
157        if(dialog)
158                Open/D refnum as fullpath+".dsmx"               //won't actually open the file
159                If(cmpstr(S_filename,"")==0)
160                        //user cancel, don't write out a file
161                        Close/A
162                        Abort "no data file was written"
163                Endif
164                fullpath = S_filename
165        Endif
166       
167        //write out partial set?
168        Duplicate/O Q_dsm,tq,ti,te
169        ti=I_dsm
170        te=S_dsm
171        if( (lo!=hi) && (lo<hi))
172                redimension/N=(hi-lo+1) tq,ti,te,res1,res2,res3         //lo to hi, inclusive
173                tq=Q_dsm[p+lo]
174                ti=I_dsm[p+lo]
175                te=S_dsm[p+lo]
176        endif
177       
178                //Data
179        Wave nf.Q = tq
180        nf.unitsQ = "1/A"
181        Wave nf.I = ti
182        nf.unitsI = "1/cm"
183        Wave nf.Idev = te
184        nf.unitsIdev = "1/cm"
185        Wave nf.Qdev = res1
186        nf.unitsQdev = "1/A"
187        Wave nf.Qmean = res2
188        nf.unitsQmean = "1/A"
189        Wave nf.Shadowfactor = res3
190        nf.unitsShadowfactor = "none"
191       
192        //tailor the output given the type of data written out...
193        String samStr="",dateStr="",str1,str2
194       
195        NVAR m = $(USANSFolder+":DSM:gPowerM")                          // power law exponent
196        NVAR chiFinal = $(USANSFolder+":DSM:gChi2Final")                //chi^2 final
197        NVAR iter = $(USANSFolder+":DSM:gIterations")           //total number of iterations
198       
199        //get the number of spline passes from the wave note
200        String noteStr
201        Variable boxPass,SplinePass
202        noteStr=note(I_dsm)
203        BoxPass = NumberByKey("BOX", noteStr, "=", ";")
204        splinePass = NumberByKey("SPLINE", noteStr, "=", ";")
205       
206        samStr = fullpath
207        dateStr="CREATED: "+date()+" at  "+time()
208        sprintf str1,"Chi^2 = %g   PowerLaw m = %4.2f   Iterations = %d",chiFinal,m,iter
209        sprintf str2,"%d box smooth passes and %d smoothing spline passes",boxPass,splinePass
210       
211        //AJJ to fix with sensible values
212        nf.run = "Test"
213        nf.nameSASinstrument = "BT5 USANS"
214        nf.SASnote = ""
215        //
216        nf.sample_ID = ""
217        nf.title = samstr
218        nf.radiation = "neutron"
219        nf.wavelength = 2.38
220        nf.unitswavelength = "A"
221       
222        //Do something with beamstop (rw[21])
223        nf.detector_name = "BT5 DETECTOR ARRAY"
224
225        nf.SASprocessnote = samStr+"\n"
226        nf.SASprocessnote += str1+"\n"
227        nf.SASprocessnote += str2+"\n"
228        nf.SASprocessnote += datestr+"\n"
229
230       
231        nf.nameSASProcess = "NIST IGOR"
232
233        //Close refnum
234       
235        writeNISTXML(fullpath, nf)
236       
237        SetDataFolder root:             //(redundant)
238       
239        KillWaves/Z res1,res2,res2,ti,te,tq
240       
241        Return(0)
242End
Note: See TracBrowser for help on using the repository browser.