source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/USANS_SlitSmearing.ipf @ 160

Last change on this file since 160 was 160, checked in by srkline, 15 years ago

Added a more graceful abort if the user cancels from the "GetSlope?" prompt

Added a report generator to the WrapperPanel?. If checked, it will generate a notebook with useful information and graph. If save is also checked, two files will be saved, the notebook, and a PNG of the graph. If save is generated without selecting "Report", nothing happens.

No changes to GaussUtils? (removed ThreadSafe? declarations from prototypes)

File size: 3.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=3.00
3#pragma IgorVersion=6.0
4
5//Functions for doing USANS Slit smearing by method of weight matrix
6//Routines originally from J Barker fortran code
7//Translated to IGOR by M-H Kim
8//Updated to use IGOR features and integrated into SANS Macros by A J Jackson
9//
10//Calculation of weights takes a while, but then each recalculation of the smeared model takes no longer
11//than the unsmeared calculation.
12//
13//Should be used when just USANS data is being fitted. Fitting of combined SANS/USANS must
14//still be done by integral method as per S Kline macros.
15//This can be avoided if IGOR Global fit is used - different functions can be fitted to the two data sets
16//with variables tied across the two. There is a loss of simplicity for the user however.
17//
18
19// AJJ
20// July 26 2007 - Modified functions to work with new SANS Analysis Macros
21//     - pass basestr to functions to determine wave names and avoid globals
22//     - pass dQv to functions to  avoid globals
23//     - pass N to CalcR to avoid globals
24
25Function USANS_CalcWeights(basestr, dQv)
26        String basestr
27        Variable dQv
28
29        Variable/G USANS_N=numpnts($(basestr+"_q"))
30        Variable/G USANS_dQv = dQv
31        String/G USANS_basestr = basestr
32
33        Make/D/O/N=(USANS_N,USANS_N) $(basestr+"_res")
34        //Make/O/N=(N,N) W1mat
35        //Make/O/N=(N,N) W2mat
36        //Make/O/N=(N,N) Rmat
37        Wave weights = $(basestr+"_res")
38
39        Variable/G USANS_m = EnterSlope()
40        if(USANS_m == 999)
41                Killwaves/Z $(basestr+"_res")
42                return(1)               //error
43        endif
44        Variable tref = startMSTimer
45        print "Calculating W1..."
46        weights = (p <= q ) && (q < USANS_N-1) ? CalcW1(p,q)  : 0
47        print "Calculating W2..."
48        weights += (p+1 <= q ) && (q < USANS_N) ?  CalcW2(p,q) : 0
49        print "Calculating Remainders..."
50        weights += (q == USANS_N-1) ? CalcR(p) : 0
51//      print "Summing weights..."
52//      Weights = W1mat + W2mat + Rmat
53        print "Done"
54        Variable ms = stopMSTimer(tref)
55        print "Time elapsed = ", ms/1e6, "s"
56        //return Weights
57End
58
59// This is far from satisfactory!
60Function EnterSlope()
61       
62        Variable slope=-4
63
64        Prompt slope "Enter a slope"
65        DoPrompt "Enter Slope", slope
66                If (V_Flag)
67                        return (999)            //return a bogus slope if the user canceled
68                Endif   
69        print "slope=", slope
70        return slope
71       
72End
73
74Function CalcW1(i,j)
75
76        Variable i,j
77        SVAR USANS_basestr
78        NVAR dQv = USANS_dQv
79       
80        Variable UU,UL,dqj,rU,rL,wU,wL,dqw
81        Wave Qval = $(USANS_basestr+"_q")
82       
83        UU =sqrt(Qval[j+1]^2-Qval[i]^2)
84        UL = sqrt(Qval[j]^2-Qval[i]^2)
85        dqw = Qval[j+1]-Qval[j]
86        rU = sqrt(UU^2+Qval[i]^2)
87        rL = sqrt(UL^2+Qval[i]^2)
88       
89        wU = (1.0/dQv)*(Qval[j+1]*UU/dqw - 0.5*UU*rU/dqw - 0.5*Qval[i]^2*ln(UU+rU)/dqw )
90        wL = (1.0/dQv)*(Qval[j+1]*UL/dqw - 0.5*UL*rL/dqw - 0.5*Qval[i]^2*ln(UL+rL)/dqw )
91       
92        Return wU-wL
93
94End
95
96Function CalcW2(i,j)
97
98        Variable i,j
99       
100        SVAR USANS_basestr
101        NVAR dQv = USANS_dQv
102       
103        variable UU,UL,dqw,rU,rL,wU,wL
104       
105        Wave Qval = $(USANS_basestr+"_q")
106
107        UU = sqrt(Qval[j]^2-Qval[i]^2)                 
108        UL = sqrt(Qval[j-1]^2-Qval[i]^2)               
109        dqw = Qval[j]-Qval[j-1]                 
110        rU = sqrt(UU^2+Qval[i]^2)
111        rL = sqrt(UL^2+Qval[i]^2)
112        wU = (1.0/dQv)*( -Qval[j-1]*UU/dqw + 0.5*UU*rU/dqw + 0.5*Qval[i]^2*ln(UU+rU)/dqw )
113        wL = (1.0/dQv)*( -Qval[j-1]*UL/dqw + 0.5*UL*rL/dqw + 0.5*Qval[i]^2*ln(UL+rL)/dqw )
114
115        Return wU-wL
116
117End
118
119Function CalcR(i)
120
121        Variable i
122
123        SVAR USANS_basestr
124        NVAR N = USANS_N
125        NVAR dQv = USANS_dQv
126       
127        Variable retval
128        Wave Qval = $(USANS_basestr+"_q")
129        Variable/G USANS_intQpt = Qval[i]
130       
131        Variable lower = sqrt(qval[N-1]^2-qval[i]^2)
132        Variable upper = lower +dQv
133       
134        retval = Integrate1D(Remainder,lower,upper)
135       
136        Return retval
137
138End
139
140Function Remainder(i)
141       
142        Variable i
143       
144        SVAR USANS_basestr
145        NVAR m = USANS_m
146        NVAR qi = USANS_intQpt
147        NVAR N = USANS_N
148        WAVE Qval = $(USANS_basestr+"_q")       
149        Variable retVal
150       
151        retVal=Qval[N-1]^(-m)*(i^2+qi^2)^(m/2)
152
153        return retval
154
155End
Note: See TracBrowser for help on using the repository browser.