I am creating a script to automate the workflow for a co-worker that is a novice JMP user. The the first operation of the script is to combine all of the iterations of data from model runs. This is accomplished by,
- The user is prompted to select the directory of the individual data tables that represent n iterations of a model run.
- The script opens all the iteration data tables that have a predefined name followed by the iteration number: “SGR Scenaio Iteration i”.
- As each iteration data table is opened, an Iteration column is added and prepopulated with the iteration number.
- After all the data tables have been opened, data tables 2 thru 10 are concatenated to the first data table, to create a new combined data table named “SGR Scenario Combined Iterations”.
- The original iterations are then closed without being saved; this is intentional to preserve the original data tables.
Here is the code for the first part of the script that accomplishes the tasks listed above:
Names Default to Here(1);
Delete Symbols();
//----------------------------------------------------------------------------------------------
// Select file path, then import and combine all iteration data tables into a single data table
// of replicates of sorties completed across iterations.
//----------------------------------------------------------------------------------------------
path = Pick Directory("Select the directory containing the iteration files.");
iterationFile = path || "SGR Scenario Iteration 1.jmp";
dtIterationTables = Open(iterationFile, "Invisible");
// add Iteration column
dtIterationTables << New Column(
"Iteration",
Ordinal,
Set Each Value(1)
);
dtIterationTables << Move Selected Columns(
{"Iteration"},
After(:Time of Day)
);
// get remaining iteration tables
i = 2;
iterationFile = path || "SGR Scenario Iteration 2.jmp";
While(File Exists(iterationFile),
nTables = i;
dtIterationFile = Open(iterationFile, "Invisible");
// add Iteration column
dtIterationFile << New Column(
"Iteration",
Ordinal,
Set Each Value(i)
);
dtIterationFile << Move Selected Columns(
{"Iteration"},
After(:Time of Day)
);
//look for next iteration table
i++;
iterationFile = path || "SGR Scenario Iteration " || Char(i) || ".jmp";
);
// concatenate current interation table to first iteration table
// NOTE: AWAITING RESPONSE ON HOW TO MAKE THIS PROCESS DYNAMIC
Data Table("SGR Scenario Iteration 1") << Concatenate(
Data Table("SGR Scenario Iteration 2"),
Data Table("SGR Scenario Iteration 3"),
Data Table("SGR Scenario Iteration 4"),
Data Table("SGR Scenario Iteration 5"),
Data Table("SGR Scenario Iteration 6"),
Data Table("SGR Scenario Iteration 7"),
Data Table("SGR Scenario Iteration 8"),
Data Table("SGR Scenario Iteration 9"),
Data Table("SGR Scenario Iteration 10"),
Output Table("SGR Scenario Combined Iterations")
);
// close original iteration tables
i = 1;
While(i <= nTables,
dtIterationTable = Data Table("SGR Scenario Iteration " || Char(i));
Close(dtIterationTable);
Clear Symbols(dtIterationTable);
i++;
);
The problem I have is with Step 4. The current script is hard-coded to concatenate 10 data tables, but I need to be able to concatenate n data tables so that my co-worker is not locked into only processing 10 iterations, or worse, having to attempt to edit the JSL code each time the size of the data set changes (read: comes to me to change the script). You can see in the code that I have a variable, nTables, that is the count of the number of data tables that were opened, as every other code block is set up to handle n data tables.
Any assistance on this matter would be greatly appreciated.