- Timestamp:
- Nov 25, 2009 4:00:25 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Common/DataSetHandling.ipf
r603 r604 13 13 // - Save a data folder to file 14 14 15 WindowDataManagementPanel()15 Function DataManagementPanel() 16 16 PauseUpdate; Silent 1 // building window... 17 NewPanel /W=(459,44,959,364)/N= wrapperPanel/K=1 as "Data Set Management"17 NewPanel /W=(459,44,959,364)/N=DataManagementPanel/K=1 as "Data Set Management" 18 18 ModifyPanel fixedSize=1 19 19 20 20 //Main bit of panel 21 GroupBox grpBox_0,pos={20,10},size={460,75} 21 GroupBox grpBox_0,pos={20,10},size={460,50} 22 GroupBox grpBox_1,pos={20,80},size={460,200} 22 23 23 24 Button DS1_button,pos={300,20},size={150,20},proc=DM_LoadDataSetProc,title="Load 1D Data Set 1" … … 25 26 PopupMenu DS1_popup,mode=1,value= #"DM_DataSetPopupList()" 26 27 27 Button DS2_button,pos={300,50},size={150,20},proc=DM_LoadDataSetProc,title="Load 1D Data Set 2" 28 PopupMenu DS2_popup,pos={30,51},size={318,20},title="Data Set 2",proc=DMDS_PopMenuProc 28 //Button DS2_button,pos={300,50},size={150,20},proc=DM_LoadDataSetProc,title="Load 1D Data Set 2" 29 //PopupMenu DS2_popup,pos={30,51},size={318,20},title="Data Set 2",proc=DMDS_PopMenuProc 30 //PopupMenu DS2_popup,mode=1,value= #"DM_DataSetPopupList()" 31 32 //Default to disabled for second data set - only needed for arithmetic 33 //Button DS2_button,disable=2 34 //PopupMenu DS2_popup,disable=2 35 36 //Tabs 37 //TabControl DSTabs,pos={20,90},size={460,200},tabLabel(0)="Management", proc=DSTabsProc 38 //TabControl DSTabs,tablabel(1)="Arithmetic" 39 //TabControl DSTabs,value=0 40 41 //Management Tab 42 Button Rename_button,title="Rename",pos={75,200},size={150,20} 43 Button Duplicate_button,title="Duplicate",pos={275,200},size={150,20} 44 Button Save_button,title="Save",pos={75,240},size={150,20} 45 Button Unload_button,title="Unload",pos={275,240},size={150,20} 46 SetVariable OldName_setvar,title="Old Name",pos={50,100},size={400,20} 47 SetVariable OldName_setvar,fsize=12,value=_STR:"",noedit=2 48 SetVariable NewName_setvar,title="New Name (max 25 characters)",pos={50,140},size={400,20} 49 SetVariable NewName_setvar,fsize=12,value=_STR:"",proc=setvarproc,live=1 50 51 End 52 53 Function MakeDAPanel() 54 55 // //Set up globals 56 // String/G root:Packages:NIST:gDA_DS1Name 57 // String/G root:Packages:NIST:gDA_DS2Name 58 // String/G root:Packages:NIST:gDA_ResultName 59 // 60 // String/G root:Packages:NIST:gDA_DS1Trace 61 // String/G root:Packages:NIST:gDA_DS2Trace 62 // String/G root:Packages:NIST:gDA_ResultTrace 63 64 65 PauseUpdate; Silent 1 // building window... 66 DoWindow/K DataArithmeticPanel 67 NewPanel /W=(459,44,959,404)/N=DataArithmeticPanel/K=1 as "Data Set Arithmetic" 68 ModifyPanel fixedSize=1 69 70 //Main bit of panel 71 GroupBox grpBox_0,pos={20,10},size={460,105} 72 73 Button DS1_button,pos={300,20},size={150,20},proc=DMDA_LoadDataSetProc,title="Load 1D Data Set 1" 74 Button DS1_button,valueColor=(65535,0,0),userdata="DS1" 75 PopupMenu DS1_popup,pos={30,21},size={318,20},title="Data Set 1" 76 PopupMenu DS1_popup,mode=1,value= #"DM_DataSetPopupList()" 77 PopupMenu DS1_popup,fsize=12,fcolor=(65535,0,0),valueColor=(65535,0,0) 78 79 Button DS2_button,pos={300,50},size={150,20},proc=DMDA_LoadDataSetProc,title="Load 1D Data Set 2" 80 Button DS2_button,valueColor=(0,0,65535),userdata="DS2" 81 PopupMenu DS2_popup,pos={30,51},size={318,20},title="Data Set 2" 29 82 PopupMenu DS2_popup,mode=1,value= #"DM_DataSetPopupList()" 30 31 //Default to disabled for second data set - only needed for arithmetic 32 Button DS2_button,disable=2 33 PopupMenu DS2_popup,disable=2 83 PopupMenu DS2_popup,fsize=12,fcolor=(0,0,65535),valueColor=(0,0,65535) 84 85 Button DSPlot_button,title="Plot",pos={175,85},size={150,20} 86 Button DSPlot_button,proc=DSPlotButtonProc 87 34 88 35 89 //Tabs 36 TabControl DSTabs,pos={20,90},size={460,200},tabLabel(0)="Management", proc=DSTabsProc 37 TabControl DSTabs,tablabel(1)="Arithmetic" 38 TabControl DSTabs,value=0 39 40 //Management Tab 41 Button DSTabItem_0a,title="Rename",pos={75,200},size={150,20} 42 Button DSTabItem_0b,title="Duplicate",pos={275,200},size={150,20} 43 Button DSTabItem_0c,title="Save",pos={75,240},size={150,20} 44 Button DSTabItem_0d,title="Unload",pos={275,240},size={150,20} 45 SetVariable DSTabItem_0e,title="Old Name",pos={50,120},size={400,20} 46 SetVariable DSTabItem_0e,fsize=12,value=_STR:"",noedit=2 47 SetVariable DSTabItem_0f,title="New Name (max 25 characters)",pos={50,150},size={400,20} 48 SetVariable DSTabItem_0f,fsize=12,value=_STR:"" 49 50 EndMacro 90 TabControl DATabs,pos={20,120},size={460,220},tabLabel(0)="Subtract", proc=DATabsProc 91 TabControl DATabs,tablabel(1)="Add",tablabel(2)="Multiply",tablabel(3)="Divide" 92 TabControl DATabs,value=0 93 94 Button DACalculate_button,title="Calculate",pos={50,310},size={150,20} 95 Button DACalculate_button,proc=DACalculateProc 96 Button DASave_button,title="Save Result",pos={300,310},size={150,20} 97 Button DACursors_button,title="Get Cursors",pos={175,250},size={150,20} 98 SetVariable DAResultName_sv,title="Result Name (max 25 characters)",pos={50,280},size={400,20} 99 SetVariable DAResultName_Sv,fsize=12,value=_STR:"SubtractionResult",proc=setvarproc,live=1 100 CheckBox DANoDS2_cb,title="Data Set 2 = 1?",pos={300,180} 101 102 ValDisplay DARangeStar_vd,title="Start",pos={40,220},size={100,20},fsize=12 103 ValDisplay DARangeEnd_vd,title="End ",pos={160,220},size={100,20},fsize=12 104 105 SetVariable DAScale_sv,title="Scale Factor (f)",pos={280,220},size={180,20},fsize=12,value=_NUM:1 106 107 GroupBox grpBox_1,pos={30,210},size={440,70} 108 109 NewPanel/HOST=DataArithmeticPanel/N=arithDisplay/W=(50,150,170,190) 110 arithDisplayProc(0) 111 112 End 113 114 Function MakeDAPlotPanel() 115 PauseUpdate; Silent 1 // building window... 116 DoWindow/K DAPlotPanel 117 NewPanel /W=(14,44,454,484)/N=DAPlotPanel/K=1 as "Data Set Arithmetic" 118 ModifyPanel fixedSize=1 119 120 Display/HOST=DAPlotPanel/N=DAPlot/W=(0,0,440,400) 121 SetActiveSubWindow DAPlotPanel 122 Checkbox DAPlot_log_cb, title="Log I(q)", pos={20,410} 123 End 124 125 126 Function DSPlotButtonProc(ba) : ButtonControl 127 STRUCT WMButtonAction &ba 128 129 String win = ba.win 130 SVAR DS1name = root:Packages:NIST:gDA_DS1Name 131 SVAR DS2name = root:Packages:NIST:gDA_DS2Name 132 SVAR Resultname = root:Packages:NIST:gDA_ResultName 133 134 switch (ba.eventCode) 135 case 2: 136 //mouse up 137 //Get folder for DS1 138 DoWindow DAPlotPanel 139 if (V_Flag == 0) 140 MakeDAPlotPanel() 141 else 142 DoWindow/HIDE=0/F DAPlotPanel 143 do 144 String tracename = StringFromList(0,TraceNameList("DAPlotPanel#DAPlot",";",1),";") 145 if (cmpstr(tracename,"")==0) 146 break 147 else 148 RemoveFromGraph/W=DAPlotPanel#DAPlot $tracename 149 endif 150 while(1) 151 endif 152 153 ControlInfo/W=$(win) DS1_popup 154 String DS1 = S_Value 155 if (cmpstr(DS1,"") != 0 ) 156 AddDAPlot(1) 157 endif 158 //Get folder for DS2 159 ControlInfo/W=$(win) DS2_popup 160 String DS2 = S_Value 161 if (cmpstr(DS2,"") != 0) 162 AddDAPlot(2) 163 endif 164 break 165 endswitch 166 167 return 0 168 End 169 170 Function AddDAPlot(dataset) 171 Variable dataset 172 173 String win = "DataArithmeticPanel" 174 175 switch(dataset) 176 case 1: 177 ControlInfo/W=$(win) DS1_popup 178 String DS1name = S_Value 179 Wave qWave = $("root:"+DS1name+":"+DS1name+"_q") 180 Wave iWave = $("root:"+DS1name+":"+DS1name+"_i") 181 Wave errWave = $("root:"+DS1name+":"+DS1name+"_s") 182 AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave 183 break 184 case 2: 185 ControlInfo/W=$(win) DS2_popup 186 String DS2name = S_Value 187 Wave qWave = $("root:"+DS2name+":"+DS2name+"_q") 188 Wave iWave = $("root:"+DS2name+":"+DS2name+"_i") 189 Wave errWave = $("root:"+DS2name+":"+DS2name+"_s") 190 AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave 191 break 192 case 3: 193 ControlInfo/W=$(win) DAResultName_sv 194 String ResultName = S_Value 195 Wave qWave = $("root:"+ResultName+":"+ResultName+"_q") 196 Wave iWave = $("root:"+ResultName+":"+ResultName+"_i") 197 Wave errWave = $("root:"+ResultName+":"+ResultName+"_s") 198 AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave 199 break 200 endswitch 201 End 202 203 Function arithDisplayProc(s) 204 Variable s 205 206 SetActiveSubWindow DataArithmeticPanel#arithDisplay 207 208 switch (s) 209 case 0: 210 //Subtract 211 DrawAction/L=progFront delete 212 DrawRect 0,0,120,40 213 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) 214 DrawText 10,32,"I" 215 SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) 216 DrawText 20,30,"=" 217 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) 218 DrawText 35,32,"I" 219 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) 220 DrawText 95,32,"I" 221 SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) 222 DrawText 52,32,"-" 223 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) 224 DrawText 75,30,"f" 225 SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) 226 DrawText 85,32,"*" 227 break 228 case 1: 229 //Add 230 DrawAction/L=progFront delete 231 DrawRect 0,0,120,40 232 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) 233 DrawText 10,32,"I" 234 SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) 235 DrawText 20,30,"=" 236 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) 237 DrawText 35,32,"I" 238 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) 239 DrawText 95,32,"I" 240 SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) 241 DrawText 52,32,"+" 242 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) 243 DrawText 75,30,"f" 244 SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) 245 DrawText 85,32,"*" 246 break 247 case 2: 248 //Multiply 249 DrawAction/L=progFront delete 250 DrawRect 0,0,120,40 251 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) 252 DrawText 10,32,"I" 253 SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) 254 DrawText 20,30,"=" 255 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) 256 DrawText 35,32,"I" 257 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) 258 DrawText 95,32,"I" 259 SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) 260 DrawText 52,32,"*" 261 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) 262 DrawText 66,30,"(" 263 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) 264 DrawText 75,30,"f" 265 SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) 266 DrawText 85,32,"*" 267 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) 268 DrawText 105,30,")" 269 break 270 case 3: 271 //Divide 272 DrawAction/L=progFront delete 273 DrawRect 0,0,120,40 274 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,65535,0) 275 DrawText 10,32,"I" 276 SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) 277 DrawText 20,30,"=" 278 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (65535,0,0) 279 DrawText 35,32,"I" 280 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,65535) 281 DrawText 95,32,"I" 282 SetDrawEnv fname="Symbol", fsize=22, fstyle= 1,textrgb= (0,0,0) 283 DrawText 52,32,"/" 284 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) 285 DrawText 66,30,"(" 286 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) 287 DrawText 75,30,"f" 288 SetDrawEnv fname="Times", fsize=22, fstyle= 1,textrgb= (0,0,0) 289 DrawText 85,32,"*" 290 SetDrawEnv fname="Times", fsize=22, fstyle= 2,textrgb= (0,0,0) 291 DrawText 105,30,")" 292 break 293 endswitch 294 295 SetActiveSubWindow DataArithmeticPanel 296 297 return 0 298 End 299 51 300 52 301 //Must follow naming scheme to match buttons to popups … … 95 344 End 96 345 346 //Must follow naming scheme to match buttons to popups 347 //"Name_button" goes with "Name_popup" 348 Function DMDA_LoadDataSetProc(ba) : ButtonControl 349 STRUCT WMButtonAction &ba 350 351 352 switch( ba.eventCode ) 353 case 2: // mouse up 354 // click code here 355 String cmd = "A_LoadOneDDataWithName(\"\","+num2str(0)+")" 356 Execute cmd 357 358 SVAR gLastFileName = root:packages:NIST:gLastFileName 359 360 String windowName = ba.win 361 String popupName = StringFromList(0,ba.ctrlName,"_")+"_popup" 362 363 ControlUpdate/W=$(windowName) $(popupName) 364 //instead of a simple controlUpdate, better to pop the menu to make sure that the other menus follow 365 // convoluted method to find the right item and pop the menu. 366 367 String list,folderStr 368 Variable num 369 folderStr = CleanupName(gLastFileName,0) 370 list = DM_DataSetPopupList() 371 num=WhichListItem(folderStr,list,";",0,0) 372 if(num != -1) 373 PopupMenu $(popupName),mode=num+1,win=$(windowName) 374 ControlUpdate/W=$(windowName) $(popupName) 375 376 endif 377 break 378 endswitch 379 380 return 0 381 End 382 383 97 384 Function DMDS_PopMenuProc(pa) : PopupMenuControl 98 385 STRUCT WMPopupAction &pa … … 101 388 case 2: // mouse up 102 389 ControlInfo/W=$(pa.win) $(pa.ctrlName) 103 SetVariable DSTabItem_0e,win=$(pa.win),value=_STR:S_Value 104 390 SetVariable OldName_setvar,win=$(pa.win),value=_STR:S_Value 391 // ControlInfo/W=$(pa.win) DSTabItem_0e 392 // SVAR val = S_Value 393 // 394 // ControlInfo/W=$(pa.win) $(pa.ctrlName) 395 // val = S_Value 396 105 397 SetDataFolder root: 106 398 break 107 399 endswitch 108 400 401 return 0 402 End 403 404 Function SetVarProc(sva) : SetVariableControl 405 STRUCT WMSetVariableAction &sva 406 407 switch( sva.eventCode ) 408 case 1: // mouse up 409 case 2: // Enter key 410 case 3: // Live update 411 String sv = sva.sval 412 if( strlen(sv) > 25 ) 413 sv= sv[0,24] 414 SetVariable $(sva.ctrlName),win=$(sva.win),value=_STR:sv 415 Beep 416 endif 417 break 418 endswitch 109 419 return 0 110 420 End … … 146 456 // in this way, buttons will always be drawn correctly.. 147 457 // 148 Function D STabsProc(name,tab)458 Function DATabsProc(name,tab) 149 459 String name 150 460 Variable tab … … 157 467 item=StringFromList(ii, ctrlList ,";") 158 468 nameStr=item[0,9] 159 if(cmpstr(nameStr,"D STabItem_")==0)469 if(cmpstr(nameStr,"DATabItem_")==0) 160 470 onTab = str2num(item[10]) 161 471 ControlInfo $item … … 177 487 endfor 178 488 179 //Deal with second data button 180 //Make sure this gets changed if the number of the Arithmetic tab changes 181 if (tab == 1) 182 Button DS2_button,disable=0 183 PopupMenu DS2_popup,disable=0 184 else 185 Button DS2_button,disable=2 186 PopupMenu DS2_popup,disable=2 187 endif 188 End 189 489 arithDisplayProc(tab) 490 End 491 492 493 Function DACalculateProc(ba) : ButtonControl 494 STRUCT WMButtonAction &ba 495 496 //Which tab? 497 ControlInfo/W=$(ba.win) DATabs 498 print V_value 499 switch(V_Value) 500 case 0: 501 print "Doing subtraction" 502 //do subtraction 503 ControlInfo/W=$(ba.win) DS1_popup 504 String DS1 = S_Value 505 ControlInfo/W=$(ba.win) DS2_popup 506 String DS2 = S_Value 507 ControlInfo/W=$(ba.win) DAResultName_sv 508 String Resultname = S_Value 509 ControlInfo/W=$(ba.win) DAScalefactor_sv 510 Variable Scalefactor = V_Value 511 SubtractDataSets(DS1,DS2,Scalefactor,Resultname) 512 case 1: 513 //do addition 514 case 2: 515 //do multiplication 516 case 3: 517 //do division 518 endswitch 519 //Do calculation 520 521 522 //Sort out plot 523 AddDAPlot(3) 524 525 End 526 527 /////// Functions to do manipulations ///////// 190 528 191 529 Function RenameDataSet(dataSetFolder, newName) … … 256 594 // Subtract Set2 From Set1 257 595 // Use Result_I = Set1_I - f*Set2_I 258 Function SubtractDataSets(set1 Folder,set2Folder,set2Scale,resultName)259 String set1 Folder260 String set2 Folder596 Function SubtractDataSets(set1Name,set2Name,set2Scale,resultName) 597 String set1Name 598 String set2Name 261 599 Variable set2Scale 262 600 String resultName 263 601 602 String set1Path = "root:"+set1Name+":" 603 String set2Path = "root:"+set2Name+":" 604 String resultPath = "root:"+resultName+":" 605 606 SetDataFolder root: 264 607 //Create folder for result 265 266 //Create result waves 608 //UnloadDataSet(resultName) 609 267 610 268 611 //Do subtraction of I waves - including interpolation if necessary. 269 612 //Can we flag when interpolation was necessary? 613 //AJJ Nov 2009 - assuming no interpolation user beware! 614 Wave result_i = $(resultPath+resultName+"_i") 615 Wave set1_i = $(set1Path+set1Name+"_i") 616 Wave set2_i = $(set2Path+set2Name+"_i") 617 result_i = set1_i - (set2Scale*set2_i) 270 618 271 619 //Generate correct result Q wave - including interpolation if necessary … … 354 702 355 703 End 704 705 706 //This will be hideous 707 Function UnloadDataSet(folderName) 708 String folderName 709 710 711 End
Note: See TracChangeset
for help on using the changeset viewer.