- Timestamp:
- Dec 1, 2009 10:02:58 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Common/DataSetHandling.ipf
r604 r607 13 13 // - Save a data folder to file 14 14 15 Function DataManagementPanel() 15 /////////////////// Data Management Panel /////////////////////////////////////////////////////// 16 17 Function MakeDMPanel() 16 18 PauseUpdate; Silent 1 // building window... 17 19 NewPanel /W=(459,44,959,364)/N=DataManagementPanel/K=1 as "Data Set Management" … … 25 27 PopupMenu DS1_popup,pos={30,21},size={318,20},title="Data Set 1",proc=DMDS_PopMenuProc 26 28 PopupMenu DS1_popup,mode=1,value= #"DM_DataSetPopupList()" 27 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_PopMenuProc30 //PopupMenu DS2_popup,mode=1,value= #"DM_DataSetPopupList()"31 32 //Default to disabled for second data set - only needed for arithmetic33 //Button DS2_button,disable=234 //PopupMenu DS2_popup,disable=235 36 //Tabs37 //TabControl DSTabs,pos={20,90},size={460,200},tabLabel(0)="Management", proc=DSTabsProc38 //TabControl DSTabs,tablabel(1)="Arithmetic"39 //TabControl DSTabs,value=040 29 41 30 //Management Tab … … 51 40 End 52 41 42 //Must follow naming scheme to match buttons to popups 43 //"Name_button" goes with "Name_popup" 44 Function DM_LoadDataSetProc(ba) : ButtonControl 45 STRUCT WMButtonAction &ba 46 47 48 switch( ba.eventCode ) 49 case 2: // mouse up 50 // click code here 51 String cmd = "A_LoadOneDDataWithName(\"\","+num2str(0)+")" 52 Execute cmd 53 54 SVAR gLastFileName = root:packages:NIST:gLastFileName 55 56 String windowName = ba.win 57 String popupName = StringFromList(0,ba.ctrlName,"_")+"_popup" 58 59 ControlUpdate/W=$(windowName) $(popupName) 60 //instead of a simple controlUpdate, better to pop the menu to make sure that the other menus follow 61 // convoluted method to find the right item and pop the menu. 62 63 String list,folderStr 64 Variable num 65 folderStr = CleanupName(gLastFileName,0) 66 list = DM_DataSetPopupList() 67 num=WhichListItem(folderStr,list,";",0,0) 68 if(num != -1) 69 PopupMenu $(popupName),mode=num+1,win=$(windowName) 70 ControlUpdate/W=$(windowName) $(popupName) 71 72 if (cmpstr(popupName,"DS1_popup") == 0) 73 //send fake mouse action to popup to update old name if 74 Struct WMPopupAction pa 75 pa.eventCode = 2 //fake mouse up 76 pa.win = windowName 77 pa.ctrlName = "DS1_popup" 78 DMDS_PopMenuProc(pa) 79 endif 80 endif 81 break 82 endswitch 83 84 return 0 85 End 86 87 88 Function DMDS_PopMenuProc(pa) : PopupMenuControl 89 STRUCT WMPopupAction &pa 90 91 switch( pa.eventCode ) 92 case 2: // mouse up 93 ControlInfo/W=$(pa.win) $(pa.ctrlName) 94 SetVariable OldName_setvar,win=$(pa.win),value=_STR:S_Value 95 // ControlInfo/W=$(pa.win) DSTabItem_0e 96 // SVAR val = S_Value 97 // 98 // ControlInfo/W=$(pa.win) $(pa.ctrlName) 99 // val = S_Value 100 101 SetDataFolder root: 102 break 103 endswitch 104 105 return 0 106 End 107 108 109 Function/S DMGetDSName(dsNum) 110 Variable dsNum 111 112 String ctrlName 113 if (dsNum == 1) 114 ctrlName = "DS1_popup" 115 elseif (dsNum == 2) 116 ctrlName = "DS2_popup" 117 endif 118 119 ControlInfo/W=DataManagementPanel $(ctrlName) 120 121 Return S_Value 122 123 End 124 125 126 /////////////////////// Data Arithmetic Panel ///////////////////////////////////////// 127 53 128 Function MakeDAPanel() 54 55 // //Set up globals56 // String/G root:Packages:NIST:gDA_DS1Name57 // String/G root:Packages:NIST:gDA_DS2Name58 // String/G root:Packages:NIST:gDA_ResultName59 //60 // String/G root:Packages:NIST:gDA_DS1Trace61 // String/G root:Packages:NIST:gDA_DS2Trace62 // String/G root:Packages:NIST:gDA_ResultTrace63 64 65 129 PauseUpdate; Silent 1 // building window... 66 130 DoWindow/K DataArithmeticPanel … … 71 135 GroupBox grpBox_0,pos={20,10},size={460,105} 72 136 73 Button DS1_button,pos={300,20},size={150,20},proc=D MDA_LoadDataSetProc,title="Load 1D Data Set 1"137 Button DS1_button,pos={300,20},size={150,20},proc=DA_LoadDataSetProc,title="Load 1D Data Set 1" 74 138 Button DS1_button,valueColor=(65535,0,0),userdata="DS1" 75 139 PopupMenu DS1_popup,pos={30,21},size={318,20},title="Data Set 1" … … 77 141 PopupMenu DS1_popup,fsize=12,fcolor=(65535,0,0),valueColor=(65535,0,0) 78 142 79 Button DS2_button,pos={300,50},size={150,20},proc=D MDA_LoadDataSetProc,title="Load 1D Data Set 2"143 Button DS2_button,pos={300,50},size={150,20},proc=DA_LoadDataSetProc,title="Load 1D Data Set 2" 80 144 Button DS2_button,valueColor=(0,0,65535),userdata="DS2" 81 145 PopupMenu DS2_popup,pos={30,51},size={318,20},title="Data Set 2" … … 83 147 PopupMenu DS2_popup,fsize=12,fcolor=(0,0,65535),valueColor=(0,0,65535) 84 148 85 Button D SPlot_button,title="Plot",pos={175,85},size={150,20}86 Button D SPlot_button,proc=DSPlotButtonProc149 Button DAPlot_button,title="Plot",pos={175,85},size={150,20} 150 Button DAPlot_button,proc=DAPlotButtonProc 87 151 88 152 … … 95 159 Button DACalculate_button,proc=DACalculateProc 96 160 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} 161 Button DASave_button,proc=DASaveProc 162 Button DACursors_button,title="Get Matching Range",pos={175,250},size={150,20} 163 Button DACursors_button,proc=DACursorButtonProc 98 164 SetVariable DAResultName_sv,title="Result Name (max 25 characters)",pos={50,280},size={400,20} 99 165 SetVariable DAResultName_Sv,fsize=12,value=_STR:"SubtractionResult",proc=setvarproc,live=1 100 166 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 167 CheckBox DANoDS2_cb,proc=DANoDS2Proc 168 169 ValDisplay DARangeStar_vd,title="Start",pos={40,220},size={100,20},fsize=12,value=_NUM:0 170 ValDisplay DARangeEnd_vd,title="End ",pos={160,220},size={100,20},fsize=12,value=_NUM:0 104 171 105 172 SetVariable DAScale_sv,title="Scale Factor (f)",pos={280,220},size={180,20},fsize=12,value=_NUM:1 … … 111 178 112 179 End 180 113 181 114 182 Function MakeDAPlotPanel() … … 119 187 120 188 Display/HOST=DAPlotPanel/N=DAPlot/W=(0,0,440,400) 189 ShowInfo 121 190 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 191 Checkbox DAPlot_log_cb, title="Log I(q)", pos={20,410},value=0 192 Checkbox DAPlot_log_cb, proc=DALogLinIProc 193 194 168 195 End 169 196 … … 172 199 173 200 String win = "DataArithmeticPanel" 201 String DS1name,DS2name,ResultName 174 202 175 203 switch(dataset) 176 204 case 1: 177 205 ControlInfo/W=$(win) DS1_popup 178 StringDS1name = S_Value206 DS1name = S_Value 179 207 Wave qWave = $("root:"+DS1name+":"+DS1name+"_q") 180 208 Wave iWave = $("root:"+DS1name+":"+DS1name+"_i") 181 209 Wave errWave = $("root:"+DS1name+":"+DS1name+"_s") 182 210 AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave 211 ErrorBars/W=DAPlotPanel#DAPlot /T=0 $(DS1name+"_i"), Y wave=(errWave,errWave) 212 ModifyGraph/W=DAPlotPanel#DAPlot rgb($(DS1name+"_i"))=(65535,0,0) 213 ControlInfo/W=$(win) DANoDS2_cb 214 // if (V_Value == 1) 215 // Cursor/W=DAPlotPanel#DAPlot A, $(DS1name+"_i"), leftx(iWave) 216 // Cursor/W=DAPlotPanel#DAPlot/A=0 B, $(DS1name+"_i"), rightx(iWave) 217 // endif 183 218 break 184 219 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 220 ControlInfo/W=$(win) DANoDS2_cb 221 if (V_Value == 0) 222 ControlInfo/W=$(win) DS2_popup 223 DS2name = S_Value 224 Wave qWave = $("root:"+DS2name+":"+DS2name+"_q") 225 Wave iWave = $("root:"+DS2name+":"+DS2name+"_i") 226 Wave errWave = $("root:"+DS2name+":"+DS2name+"_s") 227 AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave 228 ErrorBars/W=DAPlotPanel#DAPlot /T=0 $(DS2name+"_i"), Y wave=(errWave,errWave) 229 ModifyGraph/W=DAPlotPanel#DAPlot rgb($(DS2name+"_i"))=(0,0,65535) 230 Cursor/W=DAPlotPanel#DAPlot A, $(DS2name+"_i"), leftx(iWave) 231 Cursor/W=DAPlotPanel#DAPlot/A=0 B, $(DS2name+"_i"), rightx(iWave) 232 else 233 ControlInfo/W=$(win) DS1_popup 234 DS1name = S_Value 235 if (!DataFolderExists("root:NullSolvent")) 236 DuplicateDataSet("root:"+DS1name,"NullSolvent") 237 endif 238 Wave qWave =root:NullSolvent:NullSolvent_q 239 Wave iWave = root:NullSolvent:NullSolvent_i 240 Wave errWave = root:NullSolvent:NullSolvent_s 241 iWave = 1 242 errWave = 0.1 243 AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave 244 ErrorBars/W=DAPlotPanel#DAPlot /T=0 NullSolvent_i, Y wave=(errWave,errWave) 245 ModifyGraph/W=DAPlotPanel#DAPlot rgb(NullSolvent_i)=(0,0,65535) 246 Cursor/W=DAPlotPanel#DAPlot A, NullSolvent_i, leftx(iWave) 247 Cursor/W=DAPlotPanel#DAPlot/A=0 B, NullSolvent_i, rightx(iWave) 248 endif 191 249 break 192 250 case 3: 193 251 ControlInfo/W=$(win) DAResultName_sv 194 StringResultName = S_Value252 ResultName = S_Value 195 253 Wave qWave = $("root:"+ResultName+":"+ResultName+"_q") 196 254 Wave iWave = $("root:"+ResultName+":"+ResultName+"_i") 197 255 Wave errWave = $("root:"+ResultName+":"+ResultName+"_s") 198 256 AppendToGraph/W=DAPlotPanel#DAPlot iWave vs Qwave 199 break 200 endswitch 257 ErrorBars/W=DAPlotPanel#DAPlot /T=0 $(ResultName+"_i"), Y wave=(errWave,errWave) 258 ModifyGraph/W=DAPlotPanel#DAPlot rgb($(ResultName+"_i"))=(0,65535,0) 259 break 260 endswitch 261 262 ControlInfo/W=DAPlotPanel DAPlot_log_cb 263 ModifyGraph/W=DAPlotPanel#DAPlot mode=3, msize=2, marker=19, mirror=1, tick=2, log(bottom)=1,log(left)=V_Value 264 201 265 End 202 266 … … 298 362 End 299 363 300 301 364 //Must follow naming scheme to match buttons to popups 302 365 //"Name_button" goes with "Name_popup" 303 Function D M_LoadDataSetProc(ba) : ButtonControl366 Function DA_LoadDataSetProc(ba) : ButtonControl 304 367 STRUCT WMButtonAction &ba 305 306 307 switch( ba.eventCode ) 308 case 2: // mouse up 309 // click code here 310 String cmd = "A_LoadOneDDataWithName(\"\","+num2str(0)+")" 311 Execute cmd 312 313 SVAR gLastFileName = root:packages:NIST:gLastFileName 314 315 String windowName = ba.win 316 String popupName = StringFromList(0,ba.ctrlName,"_")+"_popup" 317 318 ControlUpdate/W=$(windowName) $(popupName) 319 //instead of a simple controlUpdate, better to pop the menu to make sure that the other menus follow 320 // convoluted method to find the right item and pop the menu. 321 322 String list,folderStr 323 Variable num 324 folderStr = CleanupName(gLastFileName,0) 325 list = DM_DataSetPopupList() 326 num=WhichListItem(folderStr,list,";",0,0) 327 if(num != -1) 328 PopupMenu $(popupName),mode=num+1,win=$(windowName) 329 ControlUpdate/W=$(windowName) $(popupName) 330 331 if (cmpstr(popupName,"DS1_popup") == 0) 332 //send fake mouse action to popup to update old name if 333 Struct WMPopupAction pa 334 pa.eventCode = 2 //fake mouse up 335 pa.win = windowName 336 pa.ctrlName = "DS1_popup" 337 DMDS_PopMenuProc(pa) 338 endif 339 endif 340 break 341 endswitch 342 343 return 0 344 End 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 368 352 369 switch( ba.eventCode ) 353 370 case 2: // mouse up … … 379 396 380 397 return 0 381 End382 383 384 Function DMDS_PopMenuProc(pa) : PopupMenuControl385 STRUCT WMPopupAction &pa386 387 switch( pa.eventCode )388 case 2: // mouse up389 ControlInfo/W=$(pa.win) $(pa.ctrlName)390 SetVariable OldName_setvar,win=$(pa.win),value=_STR:S_Value391 // ControlInfo/W=$(pa.win) DSTabItem_0e392 // SVAR val = S_Value393 //394 // ControlInfo/W=$(pa.win) $(pa.ctrlName)395 // val = S_Value396 397 SetDataFolder root:398 break399 endswitch400 401 return 0402 End403 404 Function SetVarProc(sva) : SetVariableControl405 STRUCT WMSetVariableAction &sva406 407 switch( sva.eventCode )408 case 1: // mouse up409 case 2: // Enter key410 case 3: // Live update411 String sv = sva.sval412 if( strlen(sv) > 25 )413 sv= sv[0,24]414 SetVariable $(sva.ctrlName),win=$(sva.win),value=_STR:sv415 Beep416 endif417 break418 endswitch419 return 0420 End421 422 // is there a simpler way to do this? I don't think so.423 Function/S DM_DataSetPopupList()424 425 String str=GetAList(4)426 427 if(strlen(str)==0)428 str = "No data loaded"429 endif430 str = SortList(str)431 432 return(str)433 End434 435 Function/S DMGetDSName(dsNum)436 Variable dsNum437 438 String ctrlName439 if (dsNum == 1)440 ctrlName = "DS1_popup"441 elseif (dsNum == 2)442 ctrlName = "DS2_popup"443 endif444 445 ControlInfo/W=DataManagementPanel $(ctrlName)446 447 Return S_Value448 449 398 End 450 399 … … 493 442 Function DACalculateProc(ba) : ButtonControl 494 443 STRUCT WMButtonAction &ba 444 445 String DS1,DS2,Resultname 446 447 switch(ba.eventCode) 448 case 2: 449 //Which tab? 450 ControlInfo/W=$(ba.win) DATabs 451 Variable tabNum = V_value 452 Print "Tab number "+num2str(tabNum) 453 454 ControlInfo/W=$(ba.win) DS1_popup 455 DS1 = S_Value 456 ControlInfo/W=$(ba.win) DANoDS2_cb 457 if (V_Value == 0) 458 ControlInfo/W=$(ba.win) DS2_popup 459 DS2 = S_Value 460 else 461 DS2 = "NullSolvent" 462 endif 463 ControlInfo/W=$(ba.win) DAResultName_sv 464 Resultname = S_Value 465 ControlInfo/W=$(ba.win) DAScale_sv 466 Variable Scalefactor = V_Value 467 468 switch(tabNum) 469 case 0: 470 //do subtraction 471 //print "Subtraction of "+DS2+" from "+DS1+" with sf "+num2str(scalefactor)+ " into "+Resultname 472 SubtractDataSets(DS1,DS2,Scalefactor,Resultname) 473 break 474 case 1: 475 //do addition 476 AddDataSets(DS1,DS2,Scalefactor,Resultname) 477 break 478 case 2: 479 //do multiplication 480 MultiplyDataSets(DS1,DS2,Scalefactor,Resultname) 481 break 482 case 3: 483 //do division 484 DivideDataSets(DS1,DS2,Scalefactor,Resultname) 485 break 486 endswitch 495 487 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 488 //Sort out plot 489 //Fake button press to DAPlotButtonProc 490 STRUCT WMButtonAction ba2 491 ba2.win = ba.win 492 ba2.ctrlName = "DAPlot_button" 493 ba2.eventCode = 2 494 DAPlotButtonProc(ba2) 495 AddDAPlot(3) 496 SetActiveSubWindow DAPlotPanel 497 DoWindow/F DataArithmeticPanel 498 endswitch 499 500 501 502 End 503 504 Function DAPlotButtonProc(ba) : ButtonControl 505 STRUCT WMButtonAction &ba 506 507 String win = ba.win 508 509 switch (ba.eventCode) 510 case 2: 511 //mouse up 512 //Get folder for DS1 513 DoWindow DAPlotPanel 514 if (V_Flag == 0) 515 MakeDAPlotPanel() 516 else 517 DoWindow/HIDE=0/F DAPlotPanel 518 do 519 String tracename = StringFromList(0,TraceNameList("DAPlotPanel#DAPlot",";",1),";") 520 if (cmpstr(tracename,"")==0) 521 break 522 else 523 RemoveFromGraph/W=DAPlotPanel#DAPlot $tracename 524 endif 525 while(1) 526 endif 527 528 ControlInfo/W=$(win) DS1_popup 529 String DS1 = S_Value 530 if (cmpstr(DS1,"") != 0 ) 531 AddDAPlot(1) 532 endif 533 //Get folder for DS2 534 ControlInfo/W=$(win) DS2_popup 535 String DS2 = S_Value 536 if (cmpstr(DS2,"") != 0) 537 AddDAPlot(2) 538 endif 539 break 540 endswitch 541 542 return 0 543 End 544 545 Function DALogLinIProc(cba) : CheckBoxControl 546 STRUCT WMCheckBoxAction &cba 547 548 switch(cba.eventcode) 549 case 2: 550 551 ModifyGraph/W=DAPlotPanel#DAPlot log(left)=cba.checked 552 553 endswitch 554 555 556 End 557 558 Function DACursorButtonProc(ba) : ButtonControl 559 STRUCT WMButtonAction &ba 560 561 String DS1,DS2 562 563 switch(ba.eventCode) 564 case 2: 565 503 566 ControlInfo/W=$(ba.win) DS1_popup 504 String DS1 = S_Value 505 ControlInfo/W=$(ba.win) DS2_popup 506 String DS2 = S_Value 567 DS1 = S_Value 568 ControlInfo/W=$(ba.win) DANoDS2_cb 569 Variable NoDS2 = V_Value 570 if (NoDS2 == 0) 571 ControlInfo/W=$(ba.win) DS2_popup 572 DS2 = S_Value 573 else 574 DS2 = "NullSolvent" 575 endif 576 577 //AJJ Nov 2009 - UGLY - Will have to revisit this when we deal with hierarchical folders 578 Wave set1_i = $("root:"+DS1+":"+DS1+"_i") 579 Wave set1_q = $("root:"+DS1+":"+DS1+"_q") 580 Wave set2_i = $("root:"+DS2+":"+DS2+"_i") 581 Wave set2_q = $("root:"+DS2+":"+DS2+"_q") 582 Duplicate/O set1_i tmp_i 583 Duplicate/O set1_q tmp_q 584 tmp_i = set1_i / interp(set1_q[p],set2_q,set2_i) 585 586 //Get cursors 587 Variable q1,q2 588 589 DoWindow/F DAPlotPanel 590 SetActiveSubWindow DAPlotPanel#DAPlot 591 592 q1 = CsrXWaveRef(A)[pcsr(A)] 593 q2 = CsrXWaveRef(B)[pcsr(B)] 594 595 //Update value display 596 ValDisplay DARangeStar_vd,value=_NUM:q1, win=$(ba.win) 597 ValDisplay DARangeEnd_vd,value=_NUM:q2, win=$(ba.win) 598 599 //Calculate scalefactor 600 601 if (NoDS2 == 1) 602 Wave avgWave = set1_i 603 else 604 Wave avgWave = tmp_i 605 endif 606 607 Variable p1 = BinarySearch(tmp_q,q1) 608 Variable p2 = BinarySearch(tmp_q,q2) 609 610 //print avgWave 611 612 WaveStats/Q/R=[p1,p2] avgWave 613 //print V_avg 614 //Update sv control 615 SetVariable DAScale_sv, value=_NUM:V_avg, win=$(ba.win) 616 617 KillWaves/Z tmp_i,tmp_q 618 DoWindow/F DataArithmeticPanel 619 endswitch 620 621 End 622 623 624 Function DANoDS2Proc(cba) : CheckBoxControl 625 STRUCT WMCheckBoxAction &cba 626 627 628 switch(cba.eventCode) 629 case 2: 630 if (cba.checked == 1) 631 //Disable DS2 popup etc 632 PopupMenu DS2_popup win=$(cba.win), disable=2 633 Button DS2_button win=$(cba.win), disable=2 634 else 635 //Enable DS2 popup etc 636 PopupMenu DS2_popup win=$(cba.win), disable=0 637 Button DS2_button win=$(cba.win), disable=0 638 endif 639 //Sort out plot 640 //Fake button press to DAPlotButtonProc 641 STRUCT WMButtonAction ba2 642 ba2.win = cba.win 643 ba2.ctrlName = "DAPlot_button" 644 ba2.eventCode = 2 645 DAPlotButtonProc(ba2) 646 SetActiveSubWindow DAPlotPanel 647 DoWindow/F DataArithmeticPanel 648 endswitch 649 650 End 651 652 Function DASaveProc(ba) : ButtonControl 653 STRUCT WMButtonAction &ba 654 655 switch(ba.eventCode) 656 case 2: 507 657 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 ///////// 658 SaveDataSetToFile(S_Value) 659 break 660 endswitch 661 662 663 End 664 665 /////////////////////// Common Panel Functions /////////////////////////////////////// 666 667 668 // is there a simpler way to do this? I don't think so. 669 Function/S DM_DataSetPopupList() 670 671 String str=GetAList(4) 672 673 if(strlen(str)==0) 674 str = "No data loaded" 675 endif 676 str = SortList(str) 677 678 return(str) 679 End 680 681 682 Function SetVarProc(sva) : SetVariableControl 683 STRUCT WMSetVariableAction &sva 684 685 switch( sva.eventCode ) 686 case 1: // mouse up 687 case 2: // Enter key 688 case 3: // Live update 689 String sv = sva.sval 690 if( strlen(sv) > 25 ) 691 sv= sv[0,24] 692 SetVariable $(sva.ctrlName),win=$(sva.win),value=_STR:sv 693 Beep 694 endif 695 break 696 endswitch 697 return 0 698 End 699 700 701 ////////////////////// Functions to do manipulations /////////////////////////////////// 528 702 529 703 Function RenameDataSet(dataSetFolder, newName) … … 539 713 basestr = ParseFilePath(0,dataSetFolder,":",1,0) 540 714 541 try542 RenameDataFolder $(dataSetFolder) $(newName) ; AbortOnRTE543 544 545 SetDataFolder $(dataSetFolderParent+newName) ; AbortOnRTE715 // try 716 RenameDataFolder $(dataSetFolder) $(newName)//; AbortOnRTE 717 718 719 SetDataFolder $(dataSetFolderParent+newName)//; AbortOnRTE 546 720 do 547 721 objName = GetIndexedObjName("",1,index) … … 553 727 while(1) 554 728 SetDataFolder root: 555 catch556 Print "Aborted: " + num2str(V_AbortCode)557 SetDataFolder root:558 endtry729 // catch 730 // Print "Aborted: " + num2str(V_AbortCode) 731 // SetDataFolder root: 732 // endtry 559 733 End 560 734 … … 572 746 basestr = ParseFilePath(0,dataSetFolder,":",1,0) 573 747 574 try 575 DuplicateDataFolder $(dataSetFolder) $(dataSetFolderParent+newName); AbortOnRTE 576 577 SetDataFolder $(dataSetFolderParent+newName); AbortOnRTE 748 SetDataFolder $(dataSetFolderParent) 749 // try 750 DuplicateDataFolder $(dataSetFolder) $(dataSetFolderParent+newName)//; AbortOnRTE 751 752 SetDataFolder $(dataSetFolderParent+newName)//; AbortOnRTE 578 753 do 579 754 objName = GetIndexedObjName("",1,index) … … 585 760 while(1) 586 761 SetDataFolder root: 587 catch 588 Print "Aborted: " + num2str(V_AbortCode) 589 SetDataFolder root: 590 endtry 762 // catch 763 // Print "Aborted: " + num2str(V_AbortCode) 764 // SetDataFolder root: 765 // 766 // endtry 591 767 End 592 768 … … 607 783 //Create folder for result 608 784 //UnloadDataSet(resultName) 609 785 if (!DataFolderExists(resultPath)) 786 //Make the folder 787 DuplicateDataSet(set1Path,resultName) 788 endif 610 789 611 790 //Do subtraction of I waves - including interpolation if necessary. 612 //Can we flag when interpolation was necessary?613 //AJJ Nov 2009 - assuming no interpolation user beware!614 791 Wave result_i = $(resultPath+resultName+"_i") 615 792 Wave set1_i = $(set1Path+set1Name+"_i") 793 Wave set1_q = $(set1Path+set1Name+"_q") 616 794 Wave set2_i = $(set2Path+set2Name+"_i") 617 result_i = set1_i - (set2Scale*set2_i)618 619 //Generate correct result Q wave - including interpolation if necessary 620 795 Wave set2_q = $(set2Path+set2Name+"_q") 796 result_i = set1_i - (set2Scale*interp(set1_q[p],set2_q,set2_i)) 797 798 621 799 //Calculate result error wave - can we produce corrected Q error? 622 800 … … 627 805 // Add Set2 to Set1 628 806 // Use Result_I = Set1_I + f*Set2_I 629 Function AddDataSets(set1 Folder,set2Folder,set2Scale,resultName)630 String set1 Folder631 String set2 Folder807 Function AddDataSets(set1Name,set2Name,set2Scale,resultName) 808 String set1Name 809 String set2Name 632 810 Variable set2Scale 633 811 String resultName 634 812 813 String set1Path = "root:"+set1Name+":" 814 String set2Path = "root:"+set2Name+":" 815 String resultPath = "root:"+resultName+":" 816 817 SetDataFolder root: 635 818 //Create folder for result 636 637 //Create result waves 819 //UnloadDataSet(resultName) 820 if (DataFolderExists(resultPath) != 1) 821 //Make the folder 822 DuplicateDataSet(set1Path,resultName) 823 endif 638 824 639 825 //Do addition of I waves - including interpolation if necessary. 640 //Can we flag when interpolation was necessary? 641 642 //Generate correct result Q wave - including interpolation if necessary 826 Wave result_i = $(resultPath+resultName+"_i") 827 Wave set1_i = $(set1Path+set1Name+"_i") 828 Wave set1_q = $(set1Path+set1Name+"_q") 829 Wave set2_i = $(set2Path+set2Name+"_i") 830 Wave set2_q = $(set2Path+set2Name+"_q") 831 result_i = set1_i + set2Scale*interp(set1_q[p],set2_q,set2_i) 643 832 644 833 //Calculate result error wave - can we produce corrected Q error? … … 650 839 // Multiply Set1 by Set2 651 840 // Use Result_I = Set1_I * (f*Set2_I) 652 Function MultiplyDataSets(set1 Folder, set2Folder, set2Scale, resultName)653 String set1 Folder654 String set2 Folder841 Function MultiplyDataSets(set1Name, set2Name, set2Scale, resultName) 842 String set1Name 843 String set2Name 655 844 Variable set2Scale 656 845 String resultName 657 846 847 String set1Path = "root:"+set1Name+":" 848 String set2Path = "root:"+set2Name+":" 849 String resultPath = "root:"+resultName+":" 850 851 SetDataFolder root: 658 852 //Create folder for result 659 660 //Create result waves 853 //UnloadDataSet(resultName) 854 if (DataFolderExists(resultPath) != 1) 855 //Make the folder 856 DuplicateDataSet(set1Path,resultName) 857 endif 661 858 662 859 //Do multiplcation of I waves - including interpolation if necessary. 663 //Can we flag when interpolation was necessary? 664 665 //Generate correct result Q wave - including interpolation if necessary 860 Wave result_i = $(resultPath+resultName+"_i") 861 Wave set1_i = $(set1Path+set1Name+"_i") 862 Wave set1_q = $(set1Path+set1Name+"_q") 863 Wave set2_i = $(set2Path+set2Name+"_i") 864 Wave set2_q = $(set2Path+set2Name+"_q") 865 result_i = set1_i*set2Scale*interp(set1_q[p],set2_q,set2_i) 866 666 867 667 868 //Calculate result error wave - can we produce corrected Q error? … … 673 874 // Divide Set1 by Set2 674 875 // Use Result_I = Set1_I / (f*Set2_I) 675 Function DivideDataSets(set1 Folder, set2Folder, set2Scale, resultName)676 String set1 Folder677 String set2 Folder876 Function DivideDataSets(set1Name, set2Name, set2Scale, resultName) 877 String set1Name 878 String set2Name 678 879 Variable set2Scale 679 880 String resultName 680 881 882 String set1Path = "root:"+set1Name+":" 883 String set2Path = "root:"+set2Name+":" 884 String resultPath = "root:"+resultName+":" 885 886 SetDataFolder root: 681 887 //Create folder for result 682 683 //Create result waves 888 //UnloadDataSet(resultName) 889 if (DataFolderExists(resultPath) != 1) 890 //Make the folder 891 DuplicateDataSet(set1Path,resultName) 892 endif 684 893 685 894 //Do division of I waves - including interpolation if necessary. 686 //Can we flag when interpolation was necessary? 687 688 //Generate correct result Q wave - including interpolation if necessary 895 Wave result_i = $(resultPath+resultName+"_i") 896 Wave set1_i = $(set1Path+set1Name+"_i") 897 Wave set1_q = $(set1Path+set1Name+"_q") 898 Wave set2_i = $(set2Path+set2Name+"_i") 899 Wave set2_q = $(set2Path+set2Name+"_q") 900 result_i = set1_i/(set2Scale*interp(set1_q[p],set2_q,set2_i) ) 689 901 690 902 //Calculate result error wave - can we produce corrected Q error? … … 693 905 694 906 End 907 908 909 ///////////////////////////Other Utility functions //////////////////////////// 695 910 696 911 Function SaveDataSetToFile(folderName) 697 912 String folderName 698 913 914 String protoStr = "" 915 //Check for history string in folder 916 //If it doesn't exist then 917 699 918 //Do saving of data file. 919 920 NVAR gXML_Write = root:Packages:NIST:gXML_Write 921 922 if (gXML_Write == 1) 923 ReWrite1DXMLData(folderName) 924 else 925 fReWrite1DData(folderName,"tab","CRLF") 926 endif 927 928 // NISTSave1DData(folderName,protoStr) 700 929 701 930 //Include history string to record what was done? … … 710 939 711 940 End 941 942 943 //////////////////// Write data functions //////////////////////////////////// 944 // AJJ Nov 2009 - should move towards unified writer 945 // 946 ////////////////////////////////////////////////////////////////////////// 947 948 //Function NISTSave1DData(folderPath,protoStr) 949 // String folderPath, protoStr 950 // 951 // //protoStr is string that will be written to either 952 // 953 // 954 //End
Note: See TracChangeset
for help on using the changeset viewer.