T O P I C R E V I E W |
Clairekun |
Posted - 07/14/2021 : 04:35:29 AM Origin Ver. and Service Release (Select Help-->About Origin): 2018b Operating System: Windows 10
Hello,
I am almost sure something like this has been addressed before but, for the life of me, I cannot find the post.
I have multiple single-sheet workbooks with names that refer to 3 measuring parameters in the form:
Long name: 150°C 16s 12% ZnO Short name: t150C16s12z
I created strings to extract all 3 parameters:
string sname$ = page.name$; string strTemp$ = sname.Betweeen("t","c")$; string strTime$ = sname.Betweeen("c","s")$; string strZnO$ = sname.Betweeen("s","z")$;
I intend to plot all books which share strTemp$ and strTime$ (i.e. all workbooks named "t150C16s..." where the last parameter varies), so I would need to compare short names among the different workbooks.
I believe I could achieve this with 2 nested loops, but I don't quite know how.
Could you please help?
Thank you. |
2 L A T E S T R E P L I E S (Newest First) |
Clairekun |
Posted - 07/19/2021 : 11:06:42 AM Hello,
I was able to discuss this with a person who, unlike me, actually had a decent background in programming and helped me get through the problem.
To sum it up, my intention was to fix 2 parameters and plot all variations of the 3rd parameter in a single graph, and repeat for all possible combinations.
Instead of comparing short names with array values, it was much faster to define a graph name that contained 2 fixed values, and then command Origin to plot all graphs to a graph window with that same name.
This way, all samples whose conditions had, say, the same temperature and time, would be plotted in the same graph, one line per %ZnO.
Maybe no one will find themselves in the need of such a thing, but here is the code, just in case. The code is long, so I will only paste one of the 3 different functions used. I tried to add idiot-proof comments so that dummies like me can understand it.
//Data has been previously imported in different books, one per sample.
//ArrSamples is a string array with all sample names.
//ArrZnO is a string array with all %ZnO values
//ArrTime is a string array with all Times
function int PlotVarTemp() //Fixed Time and %ZnO, variable Temperature
{
pe_cd /;
pe_cd path:="Data";
loop (i,1,ArrSamples.GetSize()) //Get the total number of samples (=books) and loop through their item index (i)
{
//Plot all samples and group those with the same values of Time and %ZnO in the same graph
//This means samples that share ArrTime.GetAt(i)$ value, and ArrZnO.GetAt(i)$ value
win -a %(ArrSamples.GetAt(i)$); //Activate book with item index (i)
string sNameGraph$ = "Graph" + ArrTime.GetAt(i)$ + "sec" + ArrZnO.GetAt(i)$;
plotxy iy:=[%(page.name$)]"%(layer.name$)"!(1,2) plot:=200 ogl:=[sNameGraph$];
win -a %(sNameGraph$);
}
doc -ef P
{
layer -g; //Group all lines in a graph
}
return 0;
}
//Function ends
PlotVarTemp(); //Call the created function
To plot fixed Times and Temperatures with variable %ZnO, we would only need to replace "ArrZnO" with "ArrTemp" and run the function again.
In my case, with 92 samples, the whole process of importing, renaming, collecting array strings and plotting every possible combination (a total of 67 graphs with 3-6 plots per graph) took 6 minutes. This method takes much less time that comparing names through nested loops which, with such a large amount of files, can take over an hour. |
YimingChen |
Posted - 07/14/2021 : 09:42:16 AM step 1. Prepare an empty stringArray to save the unique combination of strTemp$ and strTime$ for all workbooks.You can iterate over all workbooks by doc -e W. Then you get a stringArray like: {"t150C16s", "t200C16s", "t250C16s",...}
step 2. Iterate the stringArray. For each string in the stringArray, compare it with each workbook name (yes, a nested loop). This way for each string, you can build a range string (strRange$) as an input to the plotxy x-function. the range string should be like: ([t150C16s]1!(1,2), [t150C32s]1!(1,2), [t150C48s]1!(1,2),...)
Use the script below to plot out the range:
plotxy iy:=%(strRange$); Repeat it for all stringArray items.
James |
|
|