Hi!
I am curious about a problem that I've encountered several times now. For context, I'm writing my script in LabTalk and have integrated it into a button in Origin, so I can quickly save and run the project to see, if the code works as expected or not.
Now the problem: Usually, the script runs or fails, all within the Origin project-window. But sometimes, it just switches to the Code Builder window. It will still run the script as before, but to see the result, I have to switch into the Origin window again.
I could pinpoint the code section that seems to be responsible for this phenomenon (see code at the end). But I've experienced this behaviour in other scripts as well.
Does anyone have an idea, what this window-switch indicates or how it can be explained? Did I make an obvious mistake or does it have to do with something deeper, like run times or memory? Or is it just an annoying glitch that I shouldn't worry about? I'm curious for your ideas!
Example code section:
//geht durch alle cycles und kopiert die cyce-infozeile
for (cycle = 1; cycle <= cyclestotal; cycle++) //geht duch alle cycles
{
wrcopy iw := [%B]Rohdaten! r1 := $(cyclerow) r2 := $(cyclerow) ow := [%B]Bericht_cycle! dr1 := $(cycle); //kopiert cycle daten
stepinforow = cyclerow + 1; //zeile, in der die step-info steht
//geht im cycle durch alle steps
for (cycleend = 0; cycleend < 1;) //step-bedingung während eines cycles. ACHTUNG! das ist ein infinite loop! loopt so lange, bis die variable verändert wird.
{
//kopiert die step-infos ins bericht-wks und findet den nächsten step
wrcopy iw := [%B]Rohdaten! r1 := ($(stepinforow)) r2 := ($(stepinforow)) ow := [%B]Bericht_steps! dr1 := $(step); //kopiert die step infos
//sucht alle datenpunkte dieses steps
stependtime$ = col(4)[stepinforow]$; //merkt sich die endzeit des steps aus der step-info-zeile
stepfirstrow = stepinforow + 1; //das ist die erste datenzeile dieses steps
steplastrow = 1; //letzte zeile des steps. die 1 ist wilkürlich, wert wird erst im folgenden loop zugewiesen
for (ii = 1; ii <= rowstotal; ii++) //geht durch alle zeilen (bis zum ende, bzw. bis break kommt). das rowstotal ist hier nur eine beliebige zahl, damit es kein endelss loop ist.
{
checkrow = stepinforow + ii; //das ist die gerade betrachtete zeile
currenttime$ = col(3)[checkrow]$; //und der zugehörige zeitstempel
int islaststeprow = compare(stependtime$, currenttime$); //hier wird der zeitstempel mit dem letzten zeitstempel aus der step-info-zeile vergleichen. die variable wird 0 wenn ungleich udn 1 wenn gleich.
if (islaststeprow == 1) //abbruchbedingung (wir haben den letzten eintrag dieses steps gefunden)
{
steplastrow = checkrow;
break;
}
}
//kopiert die messdaten ins Messdaten-wks
wrcopy iw := [%B]Rohdaten! r1 := ($(stepfirstrow)) r2 := ($(steplastrow)) ow := [%B]Messdaten! dr1 := $(recordid); //kopiert die messdaten alle zusammen
recordid = recordid + (steplastrow - stepfirstrow) + 1; //das wird die erste zeilte für die daten des nächsten steps
//kopiert ausgewählte werte nach key_data
wrcopy iw := [%B]Rohdaten! c1:=8 c2:=8 r1 := ($(stepfirstrow)) r2 := ($(steplastrow)) ow := [%B]key_data! dc1 := <new>;
wrcopy iw := [%B]Rohdaten! c1:=4 c2:=4 r1 := ($(stepfirstrow)) r2 := ($(steplastrow)) ow := [%B]key_data! dc1 := <new>;
wrcopy iw := [%B]Rohdaten! c1:=3 c2:=3 r1 := ($(stepfirstrow)) r2 := ($(steplastrow)) ow := [%B]key_data! dc1 := <new>; //kopiert die daten aus den gewählten columns in neue spalten des key_data-wks
page.active$ = key_data; //aktiviert das key_data-wks
col($((3 * step - 2)))[L]$ = "Capacity Density";
col($((3 * step - 2)))[U]$ = "mAh/g";
wks.col$($(3 * step - 2)).type = 4; //ändern den plot designator (machen eine X-Spalte aus den Spalten)
col($((3 * step - 2)))[C]$ = step $(step); //fügt ein comment der form "step 1" etc. hinzu
col($((3 * step - 2) + 1))[L]$ = "Voltage";
col($((3 * step - 2) + 1))[U]$ = "V";
col($((3 * step - 2) + 1))[C]$ = step $(step);
col($((3 * step - 2) + 2))[L]$ = "Time";
col($((3 * step - 2) + 2))[U]$ = "h:mm:s.ms";
col($((3 * step - 2) + 2))[C]$ = step $(step);
page.active$ = Rohdaten; //zurück zum wks damit es weiter gehen kann
step = step + 1; //zählt die steps hoch
//prüfen, ob schon alle daten verarbeitet wurden
if (steplastrow >= rowstotal)
{
type -a "alle daten sind verarbeitet"; //#DEBUGGING
break;
}
//prüfen nach abbruchbedingung, um in den nächsten cylcle zu kommen (andernfalls gebinnt ein neuer step)
%Z = col(1)[steplastrow + 1]$; //steplastrow + 1
if (%Z >= 1)
{
cycleend = 1; //abbruchbedingung für den cycle-loop
cyclerow = steplastrow + 1; //das setzt die nächste cycle info zeile fest für den nächsten loop
}
else
{
stepinforow = steplastrow + 1;
}
} //ende step
} //ende cycle