Changeset 132 for sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/Packages/SumModel/SumSANSModels.ipf
 Timestamp:
 Jul 26, 2007 1:33:58 PM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/Packages/SumModel/SumSANSModels.ipf
r42 r132 25 25 // selections. 26 26 // 27 // TO FIX: 28 //  add a help button to call the help file 29 // ...(and write the documentation) 30 //  must be thoroughly tested... 27 // JUL 2007 28 //  data folder aware 29 //  AAO, structure aware 30 // (smeared fitting still broken) 31 //  created data folders are now buried in myGlobals 31 32 // 32 33 /////////////////////////////// … … 37 38 DoWindow/F Sum_Model_Panel 38 39 if(V_flag==0) 39 NewDataFolder/O root:SumModel 40 if(!DataFolderExists("root:myGlobals")) 41 NewDataFolder root:myGlobals 42 endif 43 NewDataFolder/O root:myGlobals:SumModel 40 44 InitSMPGlobals() 41 45 Sum_Model_Panel() … … 46 50 // 47 51 Function InitSMPGlobals() 48 Variable/G root: SumModel:gNParMod1=049 Variable/G root: SumModel:gNParMod2=052 Variable/G root:myGlobals:SumModel:gNParMod1=0 53 Variable/G root:myGlobals:SumModel:gNParMod2=0 50 54 end 51 55 … … 67 71 GroupBox group1,pos={5,50},size={216,107},title="Function # 1" 68 72 SetVariable setvar1,pos={14,128},size={140,15},title="# of Parameters" 69 SetVariable setvar1,limits={0,20,1},value= root: SumModel:gNParMod173 SetVariable setvar1,limits={0,20,1},value= root:myGlobals:SumModel:gNParMod1 70 74 GroupBox group2,pos={5,171},size={216,107},title="Function # 2" 71 75 SetVariable setvar2,pos={14,249},size={140,15},title="# of Parameters" 72 SetVariable setvar2,limits={0,20,1},value= root: SumModel:gNParMod276 SetVariable setvar2,limits={0,20,1},value= root:myGlobals:SumModel:gNParMod2 73 77 Button button0,pos={36,299},size={150,20},proc=PlotSumButtonProc,title="Plot Summed Model" 74 78 Button button1,pos={15,330},size={190,20},proc=PlotSmearedSumButtonProc,title="Plot Smeared Summed Model" … … 76 80 EndMacro 77 81 78 // show the availab elmodels82 // show the available models 79 83 // but not the smeared versions 84 // not the f* 85 // not the *X XOPS 86 // 87 // KIND:10 should show only userdefined curve fitting functions 88 //  not XOPs 89 //  not other userdefined functions 80 90 Function/S SumModelPopupList() 81 String list 82 list = FunctionList("!Smear*",";","KIND:14,NINDVARS:1") //don't show smeared models 91 String list,tmp 92 list = FunctionList("!Smear*",";","KIND:10") //don't show smeared models 93 83 94 list = RemoveFromList("Sum_Model", list ,";") 84 list = RemoveFromList("SANSModel_proto", list ,";") 95 96 tmp = FunctionList("*_proto",";","KIND:10") //prototypes 97 list = RemoveFromList(tmp, list ,";") 98 99 tmp = FunctionList("f*",";","KIND:10") //point calculations 100 list = RemoveFromList(tmp, list ,";") 101 102 // this should be a null string with KIND:10 103 tmp = FunctionList("*X",";","KIND:10") //XOPs, also point calculations 104 list = RemoveFromList(tmp, list ,";") 105 85 106 return(list) 86 107 End … … 131 152 //make the coefficients and parameters based on the panel values 132 153 Variable nParam,n1,n2 133 n1 = root: SumModel:gNParMod1134 n2 = root: SumModel:gNParMod2154 n1 = root:myGlobals:SumModel:gNParMod1 155 n2 = root:myGlobals:SumModel:gNParMod2 135 156 nParam = n1 + n2 136 157 if(n1==0  n2==0  nparam==0) … … 138 159 endif 139 160 // n is ok, keep extra copy so changing panel will not affect functions 140 Variable/G root: SumModel:gN1=n1141 Variable/G root: SumModel:gN2=n2161 Variable/G root:myGlobals:SumModel:gN1=n1 162 Variable/G root:myGlobals:SumModel:gN2=n2 142 163 143 164 // these are the function names  make global so the fit function 144 165 // can find them 145 166 ControlInfo/W=Sum_Model_Panel popup1_0 146 String/G root: SumModel:gModelStr1=S_Value167 String/G root:myGlobals:SumModel:gModelStr1=S_Value 147 168 ControlInfo/W=Sum_Model_Panel popup2_0 148 String/G root: SumModel:gModelStr2=S_Value169 String/G root:myGlobals:SumModel:gModelStr2=S_Value 149 170 150 171 //these are the coefficent waves  local only … … 164 185 parameters_sum[n1,(n1+n21)] = $paramStr2[pn1] 165 186 166 Edit parameters_sum,coef_sum 167 ywave_sum := Sum_Model(coef_sum,xwave_sum) 187 Edit parameters_sum,coef_sum 188 189 Variable/G root:g_sum 190 g_sum := Sum_Model(coef_sum,ywave_sum,xwave_sum) 168 191 Display ywave_sum vs xwave_sum 169 192 ModifyGraph log=1,marker=29,msize=2,mode=4 … … 174 197 End 175 198 199 //  sets up a dependency to a wrapper, not the actual SmearedModelFunction 176 200 // the usual macro for plotting the smeared model, updated 177 201 // to take input from the panel 178 Proc PlotSmeared_Sum_Model() 179 180 // if no gQvals wave, data must not have been loaded => abort 181 if(ResolutionWavesMissing()) 202 // 203 //  somewhat confusing as the unsmeared coefficients are in root: 204 // and all of the newly created smeared waves and coefficients are in the 205 // selected data folder 206 // 207 Proc PlotSmeared_Sum_Model(str) 208 String str 209 Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4) 210 211 // if any of the resolution waves are missing => abort 212 if(ResolutionWavesMissingDF(str)) //updated to NOT use global strings (in GaussUtils) 182 213 Abort 183 214 endif 215 216 SetDataFolder $("root:"+str) 184 217 185 218 //make the coefficients and parameters based on the panel values 186 219 Variable nParam,n1,n2 187 n1 = root: SumModel:gNParMod1188 n2 = root: SumModel:gNParMod2220 n1 = root:myGlobals:SumModel:gNParMod1 221 n2 = root:myGlobals:SumModel:gNParMod2 189 222 nParam = n1 + n2 190 223 if(n1==0  n2==0  nparam==0) … … 192 225 endif 193 226 // n is ok, keep extra copy so changing panel will not affect functions 194 Variable/G root: SumModel:gN1=n1195 Variable/G root: SumModel:gN2=n2227 Variable/G root:myGlobals:SumModel:gN1=n1 228 Variable/G root:myGlobals:SumModel:gN2=n2 196 229 197 230 // these are the function names  make global so the fit function 198 231 // can find them 199 232 ControlInfo/W=Sum_Model_Panel popup1_0 200 String/G root: SumModel:gModelStr1=S_Value233 String/G root:myGlobals:SumModel:gModelStr1=S_Value 201 234 ControlInfo/W=Sum_Model_Panel popup2_0 202 String/G root: SumModel:gModelStr2=S_Value203 204 //these are the coefficent waves  local only 235 String/G root:myGlobals:SumModel:gModelStr2=S_Value 236 237 //these are the coefficent waves  local only, in the current data folder! 205 238 ControlInfo/W=Sum_Model_Panel popup1_1 206 String/G root:coefStr1=S_Value239 String/G coefStr1=S_Value 207 240 ControlInfo/W=Sum_Model_Panel popup2_1 208 String/G root:coefStr2=S_Value241 String/G coefStr2=S_Value 209 242 210 243 Make/O/D/N=(nParam) smear_coef_sum 211 smear_coef_sum[0,(n11)] = $ coefStr1212 smear_coef_sum[n1,(n1+n21)] = $ coefStr2[pn1]244 smear_coef_sum[0,(n11)] = $("root:"+coefStr1) 245 smear_coef_sum[n1,(n1+n21)] = $("root:"+coefStr2)[pn1] 213 246 214 247 make/o/t/N=(nParam) smear_parameters_sum 215 248 String paramStr1 = "parameters"+coefStr1[4,strlen(coefStr1)1] 216 249 String paramStr2 = "parameters"+coefStr2[4,strlen(coefStr2)1] 217 smear_parameters_sum[0,(n11)] = $ paramStr1218 smear_parameters_sum[n1,(n1+n21)] = $ paramStr2[pn1]250 smear_parameters_sum[0,(n11)] = $("root:"+paramStr1) 251 smear_parameters_sum[n1,(n1+n21)] = $("root:"+paramStr2)[pn1] 219 252 220 253 Edit smear_parameters_sum,smear_coef_sum … … 222 255 // output smeared intensity wave, dimensions are identical to experimental QSIG values 223 256 // make extra copy of experimental qvalues for easy plotting 224 Duplicate/O $ gQvalssmeared_sum,smeared_qvals257 Duplicate/O $(str+"_q") smeared_sum,smeared_qvals 225 258 SetScale d,0,0,"1/cm",smeared_sum 226 227 smeared_sum := Smeared_Sum_Model(smear_coef_sum,$gQvals) 228 Display smeared_sum vs $gQvals 259 260 Variable/G gs_sum=0 261 gs_sum := fSmeared_Sum_Model(smear_coef_sum,smeared_sum,smeared_qvals) //this wrapper fills the STRUCT 262 263 Display smeared_sum vs $(str+"_q") 229 264 ModifyGraph log=1,marker=29,msize=2,mode=4 230 265 Label bottom "q (\\S1\\M)" … … 232 267 Legend 233 268 AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) 269 270 SetDataFolder root: 234 271 End 235 272 … … 238 275 // sum of the two selected models. 239 276 // 240 Function Sum_Model(w,x) :FitFunc 241 Wave w;Variable x 242 243 SVAR funcStr1=root:SumModel:gModelStr1 //string names of the functions, set by the macro 244 SVAR funcStr2=root:SumModel:gModelStr2 245 NVAR n1=root:SumModel:gN1 //number of coefficients, set by the macro 246 NVAR n2=root:SumModel:gN2 277 // this is an AAO function, there is no XOP version 278 // since it should be the sum of two XOPs 279 // 280 Function Sum_Model(w,yw,xw) : FitFunc 281 Wave w,yw,xw 282 283 SVAR funcStr1=root:myGlobals:SumModel:gModelStr1 //string names of the functions, set by the macro 284 SVAR funcStr2=root:myGlobals:SumModel:gModelStr2 285 NVAR n1=root:myGlobals:SumModel:gN1 //number of coefficients, set by the macro 286 NVAR n2=root:myGlobals:SumModel:gN2 247 287 248 288 Variable retVal 249 289 250 FUNCREF SANSModel _proto f1 = $funcStr1 //convert str to FCN251 FUNCREF SANSModel _proto f2 = $funcStr2290 FUNCREF SANSModelAAO_proto f1 = $funcStr1 //convert str to FCN 291 FUNCREF SANSModelAAO_proto f2 = $funcStr2 252 292 // make temporary coefficient waves for each model 253 293 Make/O/D/N=(n1) temp_cw1 … … 256 296 temp_cw2 = w[p+n1] 257 297 258 // calculate the sum 259 retVal = f1(temp_cw1,x) + f2(temp_cw2,x) 260 return(retVal) 298 // calculate the sum of each of the AAO functions 299 Duplicate/O xw tmp_sum_yw1,tmp_sum_yw2 300 301 f1(temp_cw1,tmp_sum_yw1,xw) 302 f2(temp_cw2,tmp_sum_yw2,xw) 303 yw = tmp_sum_yw1 + tmp_sum_yw2 304 305 return(0) 261 306 end 262 307 263 308 // this is all there is to the smeared calculation! 264 Function Smeared_Sum_Model(w,x) :FitFunc 265 Wave w 266 Variable x 267 268 Variable ans 269 SVAR sq = gSig_Q 270 SVAR qb = gQ_bar 271 SVAR sh = gShadow 272 SVAR gQ = gQVals 273 274 //the name of your unsmeared model is the first argument 275 ans = Smear_Model_20(Sum_Model,$sq,$qb,$sh,$gQ,w,x) 276 277 return(ans) 309 Function Smeared_Sum_Model(s) : FitFunc 310 Struct ResSmearAAOStruct &s 311 312 // the name of your unsmeared model (AAO) is the first argument 313 s.yW = Smear_Model_20(Sum_Model,s.coefW,s.xW,s.resW) 314 315 return(0) 316 End 317 318 //wrapper to calculate the smeared model as an AAOStruct 319 // fills the struct and calls the ususal function with the STRUCT parameter 320 // 321 // used only for the dependency, not for fitting 322 // 323 Function fSmeared_Sum_Model(coefW,yW,xW) 324 Wave coefW,yW,xW 325 326 String str = getWavesDataFolder(yW,0) 327 String DF="root:"+str+":" 328 329 WAVE resW = $(DF+str+"_res") 330 331 STRUCT ResSmearAAOStruct fs 332 WAVE fs.coefW = coefW 333 WAVE fs.yW = yW 334 WAVE fs.xW = xW 335 WAVE fs.resW = resW 336 337 Variable err 338 err = Smeared_Sum_Model(fs) 339 340 return (0) 278 341 End 279 342
Note: See TracChangeset
for help on using the changeset viewer.