Changeset 165
- Timestamp:
- Sep 20, 2007 10:59:50 AM (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/Wrapper.ipf
r161 r165 7 7 // 8 8 // 9 10 Macro OpenWrapperPanel() 11 Init_WrapperPanel() 12 End 13 14 Function Init_WrapperPanel() 15 DoWindow/F WrapperPanel 16 if(V_flag==0) 17 if(exists("root:coefKWStr")==0) 18 String/G root:coefKWStr="" 19 endif 20 if(exists("root:suffixKWStr")==0) 21 String/G root:suffixKWStr="" 22 endif 23 Execute "WrapperPanel()" 24 endif 25 End 26 9 27 //////// 10 28 // … … 17 35 // and put these in the table as needed 18 36 // 19 Window WrapperPanel() : Panel37 Window WrapperPanel() 20 38 PauseUpdate; Silent 1 // building window... 21 39 NewPanel /W=(459,44,1113,499)/N=wrapperPanel as "Curve Fit Setup" … … 28 46 Button button_1,pos={270,57},size={80,20},proc=PlotModelFunction,title="Plot" 29 47 Button button_2,pos={270,93},size={80,20},proc=AppendModelToTarget,title="Append" 48 Button button_3,pos={270,20},size={80,20},proc=W_LoadDataButtonProc,title="Load Data" 30 49 PopupMenu popup_0,pos={30,21},size={218,20},title="Data Set" 31 50 PopupMenu popup_0,mode=1,value= #"W_DataSetPopupList()" 32 51 PopupMenu popup_1,pos={30,57},size={136,20},title="Function" 33 PopupMenu popup_1,mode=1,value= #"W_FunctionPopupList()" 52 PopupMenu popup_1,mode=1,value= #"W_FunctionPopupList()",proc=Function_PopMenuProc 34 53 PopupMenu popup_2,pos={30,93},size={123,20},title="Coefficients" 35 54 PopupMenu popup_2,mode=1,value= #"W_CoefPopupList()",proc=Coef_PopMenuProc … … 37 56 CheckBox check_1,pos={400,42},size={74,14},title="Use Epsilon?",value= 0 38 57 CheckBox check_2,pos={400,65},size={95,14},title="Use Constraints?",value= 0 39 CheckBox check_3,pos={ 280,24},size={72,14},title="From target",value= 058 CheckBox check_3,pos={544,18},size={72,14},title="From target",value= 0 40 59 CheckBox check_4,pos={400,85},size={72,14},title="Report?",value= 0 41 CheckBox check_5,pos={414,10 0},size={72,14},title="Save it?",value= 060 CheckBox check_5,pos={414,103},size={72,14},title="Save it?",value= 0 42 61 Edit/W=(20,174,634,435)/HOST=# 43 62 ModifyTable width(Point)=0 … … 46 65 EndMacro 47 66 67 //obvious use 68 Function W_LoadDataButtonProc(ba) : ButtonControl 69 STRUCT WMButtonAction &ba 70 71 switch( ba.eventCode ) 72 case 2: // mouse up 73 // click code here 74 String topGraph= WinName(0,1) 75 if(strlen(topGraph) != 0) 76 DoWindow/F $topGraph //so that the panel is not on top 77 endif 78 Execute "LoadSANSorUSANSData()" 79 break 80 endswitch 81 82 return 0 83 End 84 48 85 49 86 // is there a simpler way to do this? … … 52 89 String str=GetAList(4),tmp="",onTargetStr="" 53 90 Variable ii 54 ControlInfo check_391 ControlInfo/W=WrapperPanel check_3 55 92 if(V_Value==1) //if "from target" checked 56 93 //ther must be a better way to do this … … 121 158 End 122 159 160 123 161 // show all the appropriate coefficient waves 124 162 // … … 127 165 // 128 166 // - or - restrict the coefficient list based on the model function 129 // 167 // - new way, filter the possible values based on the data folder and function 130 168 Function/S W_CoefPopupList() 131 String list 132 setDataFolder root: 133 list = WaveList("coef*",";","") 134 169 170 String notPlotted="Please plot the function" 171 ControlInfo/W=wrapperpanel popup_1 172 String funcStr=S_Value 173 String coefStr=getFunctionCoef(funcStr) 174 175 if(cmpstr(coefStr,"")==0) //no correspondence in the KW string 176 return(notPlotted) 177 endif 178 179 180 //found a coefficient wave - only two places to look 181 // is it in the root folder? 182 if(exists("root:"+coefStr) != 0) 183 return(coefStr) 184 endif 185 186 // is it in the data folder? 135 187 ControlInfo/W=wrapperpanel popup_0 136 if(V_Value != 0) //0== no items in menu 137 if(DataFolderExists("root:"+S_Value)) 138 SetDataFolder $("root:"+S_Value) 139 list += WaveList("*coef*",";","") 140 endif 141 endif 142 143 // tmp coefficients that aren't being cleaned up from somewhere... 144 list = RemoveFromList("temp_coef_1;temp_coef_2;", list ,";") 145 146 if(strlen(list)==0) 147 list = "No functions plotted" 148 endif 149 list = SortList(list) 150 151 // Print itemsinlist(list,";") 152 153 setDataFolder root: 154 return(list) 155 End 188 String folderStr=S_Value 189 if(exists("root:"+folderStr+":"+coefStr) != 0) 190 return(coefStr) 191 endif 192 193 return(notPlotted) 194 End 195 196 // show all the appropriate coefficient waves 197 // 198 // also need to search the folder listed in "data set" popup 199 // for smeared coefs 200 // 201 // - or - restrict the coefficient list based on the model function 202 // 203 // --old way 204 //Function/S W_CoefPopupList() 205 // String list 206 // setDataFolder root: 207 // list = WaveList("coef*",";","") 208 // 209 // ControlInfo/W=wrapperpanel popup_0 210 // if(V_Value != 0) //0== no items in menu 211 // if(DataFolderExists("root:"+S_Value)) 212 // SetDataFolder $("root:"+S_Value) 213 // list += WaveList("*coef*",";","") 214 // endif 215 // endif 216 // 217 // // tmp coefficients that aren't being cleaned up from somewhere... 218 // list = RemoveFromList("temp_coef_1;temp_coef_2;", list ,";") 219 // 220 // if(strlen(list)==0) 221 // list = "No functions plotted" 222 // endif 223 // list = SortList(list) 224 // 225 //// Print itemsinlist(list,";") 226 // 227 // setDataFolder root: 228 // return(list) 229 //End 156 230 157 231 // if the coefficients are changed, then update the table … … 171 245 String popStr = pa.popStr 172 246 String suffix = getModelSuffix(popStr) 173 ControlInfo popup_0247 ControlInfo/W=WrapperPanel popup_0 174 248 String folderStr=S_Value 175 249 250 if(cmpstr(popStr,"Please plot the function")==0) 251 Print "function not plotted" 252 return(0) 253 endif 254 255 // this if/else/endif should not ever return an error alert 256 // it should simply set the data folder properly 176 257 if(DataFolderExists("root:"+folderStr)) 177 258 SetDataFolder $("root:"+folderStr) … … 180 261 SetDataFolder root: 181 262 if(!exists(popStr)) //this should be fine if the coef filter is working, but check anyhow 182 DoAlert 0,"the coefficient and data sets do not match "263 DoAlert 0,"the coefficient and data sets do not match (1)" 183 264 return 0 184 265 endif … … 188 269 SetDataFolder root: 189 270 if(!exists(popStr)) //this should be fine if the coef filter is working, but check anyhow 190 DoAlert 0,"the coefficient and data sets do not match "271 DoAlert 0,"the coefficient and data sets do not match (2)" 191 272 return 0 192 273 endif … … 196 277 Variable num=numpnts($popStr) 197 278 // make the necessary waves 198 Make/O/D/N=(num) $("epsilon "+suffix),$("Hold"+suffix)199 Make/O/T/N=(num) $("LoLim "+suffix),$("HiLim"+suffix)279 Make/O/D/N=(num) $("epsilon_"+suffix),$("Hold_"+suffix) 280 Make/O/T/N=(num) $("LoLim_"+suffix),$("HiLim_"+suffix) 200 281 201 282 // default epsilon values, sometimes needed for the fit 202 Wave eps = $("epsilon "+suffix)283 Wave eps = $("epsilon_"+suffix) 203 284 Wave coef=$popStr 204 285 eps = abs(coef*1e-4) + 1e-10 //default eps is proportional to the coefficients 205 WAVE/T LoLim = $("LoLim "+suffix)206 WAVE/T HiLim = $("HiLim "+suffix)286 WAVE/T LoLim = $("LoLim_"+suffix) 287 WAVE/T HiLim = $("HiLim_"+suffix) 207 288 LoLim = "" //should have nicer way of keeping the previous values 208 289 HiLim = "" … … 216 297 String param = WaveList("*param*"+suffix, "", "TEXT:1," ) //this is *hopefully* one wave 217 298 AppendtoTable/W=wrapperPanel#T0 $param,$(popStr) 218 AppendToTable/W=wrapperPanel#T0 $("Hold "+suffix),$("LoLim"+suffix),$("HiLim"+suffix),$("epsilon"+suffix)299 AppendToTable/W=wrapperPanel#T0 $("Hold_"+suffix),$("LoLim_"+suffix),$("HiLim_"+suffix),$("epsilon_"+suffix) 219 300 ModifyTable width(Point)=0 220 301 … … 225 306 return 0 226 307 End 308 309 // if the Function is changed, then update the coef popup (if possible) and then the table (if possible) 310 // 311 // !! only respond to mouse up 312 // 313 Function Function_PopMenuProc(pa) : PopupMenuControl 314 STRUCT WMPopupAction &pa 315 316 switch( pa.eventCode ) 317 case 2: // mouse up 318 Variable popNum = pa.popNum 319 String funcStr = pa.popStr 320 String coefStr = W_CoefPopupList() 321 322 // Print "coefStr = ",coefStr 323 324 ControlInfo/W=WrapperPanel popup_0 325 String folderStr=S_Value 326 327 String listStr = W_CoefPopupList() 328 Variable num=WhichListItem(coefStr, listStr, ";") 329 String str=StringFromList(num, listStr ,";") 330 // print "str = ",str 331 //set the item in the coef popup, and pop it 332 PopupMenu popup_2 mode=(num+1) 333 334 Struct WMPopupAction ps 335 ps.eventCode = 2 //fake mouse up 336 ps.popStr = str 337 Coef_PopMenuProc(ps) 338 339 SetDataFolder root: 340 break 341 endswitch 342 343 return 0 344 End 345 227 346 228 347 // always pass this the coefficient string … … 231 350 // or "smear_coef_" 232 351 // 352 Function/S getFunctionCoef(funcStr) 353 String funcStr 354 355 SVAR listStr=root:coefKWStr 356 String coefStr = StringByKey(funcStr, listStr ,"=",";",0) 357 358 return(coefStr) 359 End 360 361 // always pass this the coefficient string 362 // 363 // either "coef_" 364 // or "smear_coef_" 365 // 366 // does NOT return the leading "_" as part of the suffix 233 367 Function/S getModelSuffix(coefStr) 234 368 String coefStr 235 369 236 Variable pos,start=0 237 // Variable pos=Strsearch(modelStr,"_",Inf,1) //look backwards to find "_" - this fails for form+struct models 238 239 if(stringmatch(coefStr,"smear_*") == 1) 240 start=7 //look forwards to find "_", skipping "smear_coe" if necessary 241 endif 242 pos=Strsearch(coefStr,"_",start,0) 370 SVAR listStr=root:suffixKWStr 371 String suffixStr = StringByKey(coefStr, listStr ,"=",";",0) 372 373 return(suffixStr) 374 // Variable pos,start=0 375 376 // if(stringmatch(coefStr,"smear_*") == 1) 377 // start=7 //look forwards to find "_", skipping "smear_coe" if necessary 378 // endif 379 // pos=Strsearch(coefStr,"_",start,0) 243 380 //Print start, pos 244 return(coefStr[pos,strlen(coefStr)-1])381 // return(coefStr[pos,strlen(coefStr)-1]) 245 382 End 246 383 … … 266 403 switch( ba.eventCode ) 267 404 case 2: // mouse up 268 ControlInfo popup_0405 ControlInfo/W=WrapperPanel popup_0 269 406 folderStr=S_Value 270 407 271 ControlInfo popup_1408 ControlInfo/W=WrapperPanel popup_1 272 409 funcStr=S_Value 273 410 … … 283 420 //Print cmdStr 284 421 Execute cmdStr 422 423 //pop the function menu to set the proper coefficients 424 DoWindow/F WrapperPanel 425 STRUCT WMPopupAction pa 426 pa.popStr = funcStr 427 pa.eventcode = 2 428 Function_PopMenuProc(pa) 429 285 430 break 286 431 endswitch … … 300 445 switch( ba.eventCode ) 301 446 case 2: // mouse up 302 ControlInfo popup_2447 ControlInfo/W=WrapperPanel popup_2 303 448 coefStr=S_Value 304 449 suffix = getModelSuffix(coefStr) … … 307 452 if(stringmatch(coefStr, "smear*" )==1) 308 453 //it's a smeared model 309 ControlInfo popup_0454 ControlInfo/W=WrapperPanel popup_0 310 455 folderStr=S_Value 311 456 xWStr = "root:"+folderStr+":smeared_qvals" 312 ywStr = "root:"+folderStr+":smeared "+suffix457 ywStr = "root:"+folderStr+":smeared_"+suffix 313 458 else 314 459 // it's not, so it's in the root folder 315 xWStr = "xwave"+suffix 316 yWStr = "ywave"+suffix 317 endif 318 319 Wave yw = $yWStr 320 Wave xw = $xWStr 321 AppendtoGraph yw vs xw 460 xWStr = "xwave_"+suffix 461 yWStr = "ywave_"+suffix 462 endif 463 464 Wave/Z yw = $yWStr 465 Wave/Z xw = $xWStr 466 if(WaveExists(yw) && WaveExists(xw)) 467 AppendtoGraph yw vs xw 468 else 469 DoAlert 0,"The selected model has not been plotted for the selected data set." 470 endif 322 471 break 323 472 endswitch … … 336 485 switch( ba.eventCode ) 337 486 case 2: // mouse up 338 ControlInfo popup_0487 ControlInfo/W=WrapperPanel popup_0 339 488 folderStr=S_Value 340 489 341 ControlInfo popup_1490 ControlInfo/W=WrapperPanel popup_1 342 491 funcStr=S_Value 343 492 344 ControlInfo popup_2493 ControlInfo/W=WrapperPanel popup_2 345 494 coefStr=S_Value 346 495 347 Control infocheck_0496 ControlInfo/W=WrapperPanel check_0 348 497 useCursors=V_Value 349 Control infocheck_1498 ControlInfo/W=WrapperPanel check_1 350 499 useEps=V_Value 351 Control infocheck_2500 ControlInfo/W=WrapperPanel check_2 352 501 useConstr=V_Value 502 503 if(!CheckFunctionAndCoef(funcStr,coefStr)) 504 DoAlert 0,"The coefficients and function type do not match. Please correct the selections in the popup menus." 505 break 506 endif 353 507 354 508 FitWrapper(folderStr,funcStr,coefStr,useCursors,useEps,useConstr) … … 370 524 End 371 525 526 Function CheckFunctionAndCoef(funcStr,coefStr) 527 String funcStr,coefStr 528 529 SVAR listStr=root:coefKWStr 530 String properCoefStr = StringByKey(funcStr, listStr ,"=",";",0) 531 if(cmpstr(coefStr,properCoefStr)==0) 532 return(1) //true, the coef is the correct match 533 endif 534 return(0) //false, wrong coef 535 End 372 536 373 537 ///////////////////////////////// … … 396 560 397 561 WAVE cw=$(coefStr) 398 Wave hold=$("Hold "+suffix)399 Wave/T lolim=$("LoLim "+suffix)400 Wave/T hilim=$("HiLim "+suffix)401 Wave eps=$("epsilon "+suffix)562 Wave hold=$("Hold_"+suffix) 563 Wave/T lolim=$("LoLim_"+suffix) 564 Wave/T hilim=$("HiLim_"+suffix) 565 Wave eps=$("epsilon_"+suffix) 402 566 403 567 // fill a struct instance whether I need one or not … … 577 741 578 742 Variable yesSave=0,yesReport=0 579 ControlInfo check_4743 ControlInfo/W=WrapperPanel check_4 580 744 yesReport = V_Value 581 ControlInfo check_5745 ControlInfo/W=WrapperPanel check_5 582 746 yesSave = V_Value 583 747
Note: See TracChangeset
for help on using the changeset viewer.