#pragma rtGlobals=1 // Use modern global access method. // To try these procedures, execute the following in a new experiment: // Make/O/N=5 xA1=p, yA1=p+1, yA2=p+2 // Make/O/N=5 xB1=p, yB1=p+1, yB2=p+2 // Edit xA1, yA1, yA2 // AppendToTable xB1, yB1, yB2 // // Select xA1 in the table and choose Macros->Select XY Pair A // Select xA2 in the table and choose Macros->Select XY Pair B // // Open the Data Browser and inspect the global strings created by the procedure. // The string names start with gSupra. // // 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, 1 // Get selection row and column indices Variable startColumn = V_startCol // Index of first selected column - assumed to be x wave // First selected column is assumed to be x1 Wave x1 = WaveRefIndexed(tableName, startColumn, 1) String xName = NameOfWave(x1) String x1Path = GetWavesDataFolder(x1, 2) // Second column after first selected column is assumed to be y2 Wave y2 = WaveRefIndexed(tableName, startColumn+2, 1) String y2Name = NameOfWave(y2) String y2Path = GetWavesDataFolder(y2, 2) // 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 = x1Path, root:gSupraYWaveAPath=y2Path // Save for future use Printf "XY pair A set to: %s, %s\r", x1Path, y2Path else String/G root:gSupraXWaveBPath = x1Path, root:gSupraYWaveBPath=y2Path // Save for future use Printf "XY pair B set to: %s, %s\r", x1Path, y2Path 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