#pragma rtGlobals=1 // Use modern global access method. // To try these procedures, execute the following in a new experiment: // Make/O/N=5 x1=p, y1=p // Make/O/N=5 x2=2*p, y2=2*p // Edit x1, y1, x2, y2 // // Select x1 and y1 in the table and choose Macros->Select XY Pair A // Select x2 and y2 in the table and choose Macros->Select XY Pair B // // Now read the code. This is just a skeleton starting point. Making it slick // and bulletproof is much more work. Menu "Macros" "Select XY Pair A/1", SelectXYPairFromTopTable(0) "Select XY Pair B/2", SelectXYPairFromTopTable(1) "Create Dif/3", CreateDif("TestDif") // Will always overwrite wave TestDif. A more sophisticated approach is needed. End Function SelectXYPairFromTopTable(AorB) Variable AorB // 0 for A, 1 for B String tableName = WinName(0, 2, 1) if (strlen(tableName) == 0) Abort "There are no tables" endif GetSelection table, $tableName, 6 // Get column and data folder names String columnNameList = S_selection // S_selection is set by GetSelection String dataFolderNameList = S_dataFolder // S_dataFolder is set by GetSelection Variable numColumnsSelected = ItemsInList(columnNameList) if (numColumnsSelected != 2) Abort "Selected exactly two columns, X and Y" endif String xName = StringFromList(0, columnNameList) xName = RemoveEnding(xName, ".d") // Convert column name to wave name String yName = StringFromList(1, columnNameList) yName = RemoveEnding(yName, ".d") // Convert column name to wave name String xDF = StringFromList(0, dataFolderNameList) String yDF = StringFromList(1, dataFolderNameList) String xPath = xDF + xName String yPath = yDF + yName // NOTE: This code stores this procedure file's private variables in the root data folder. // This is OK for elementary programming but is not used in sophisticated programming // because it causes clutter and exposes too much information to the end user. // The simple approach is OK for starting but if you are going to create a robust package, // execute this and learn about Packages: // DisplayHelpTopic "Packages" // DisplayHelpTopic "Managing Package Data" if (AorB == 0) String/G root:gSupraXWaveAPath = xPath, root:gSupraYWaveAPath=yPath // Save for future use Printf "XY pair A set to: %s, %s\r", xPath, yPath else String/G root:gSupraXWaveBPath = xPath, root:gSupraYWaveBPath=yPath // Save for future use Printf "XY pair B set to: %s, %s\r", xPath, yPath endif End // NOTE: This is wrong because it doesn't take the X waves into account and assumes // that the lengths of the waves are equal. A more sophisticated approach is left // as an exercise for the reader. Function CreateDif(outputWaveName) String outputWaveName // Get Y wave A SVAR/Z supraYWaveAPath = root:gSupraYWaveAPath if (!SVAR_Exists(supraYWaveAPath)) Abort "Set the A and B XY pairs before creating the difference" endif Wave supraYWaveA = $supraYWaveAPath // Get Y wave B SVAR/Z supraYWaveBPath = root:gSupraYWaveBPath if (!SVAR_Exists(supraYWaveBPath)) Abort "Set the A and B XY pairs before creating the difference" endif Wave supraYWaveB = $supraYWaveBPath // Create difference Duplicate /O supraYWaveA, $outputWaveName Wave dif = $outputWaveName dif -= supraYWaveB String tableName = WinName(0, 2, 1) if (strlen(tableName) != 0) AppendToTable dif // This assumes that we want to append to the top table endif Printf "Created dif: %s = %s - %s\r", outputWaveName, supraYWaveAPath, supraYWaveBPath End