The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Dataset loop error

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
LabTalk user Posted - 02/29/2012 : 7:26:31 PM
Origin Ver. and Service Release (Select Help-->About Origin): 8.1 SR3
Operating System: Windows XP

Hello,

I am looping through some code and defining two datsets within the loop. The datasets get defined every time through and are subsequently used. However, in the last loop the second dataset doesn't get defined. It is defined as the subtraction of two previously defined range variables. (i.e. dataset z = x-y) Has anyone else come across this issue or have an idea of how to troubleshoot this error?

Thanks,
Patrick
5   L A T E S T    R E P L I E S    (Newest First)
greg Posted - 03/12/2012 : 11:35:25 AM
It would take too long to setup a project file that would work with your code which appears to be a section of a larger file that accepts one argument.
The only thing that jumps out at me is that you have used a variable named Y. Y is a reserved System Variable, which means Origin might use it at some point which would overwrite your use.
I don't see any particular reason why that may be happening, but as a precaution (and a test) try using a different name, such as replacing all
$(y) with $(arg1)
$(y-1) with $(arg1-1)
*y) with *arg1)
and change
y = %1;
to
arg1 = %1;

Since you have an OGS file, you should be debugging in Code Builder. In debug, you can hover the mouse over a variable to see its value or you can setup Watch values. Your comment that it works OK for a separate section of the data suggests that it fails because you read some bad value for the data where the code fails.
LabTalk user Posted - 03/09/2012 : 7:05:25 PM
The following code is run within the loop. It is called as a section.

/* Defines %1 temporary variable with an actual variable */
y = %1;

/* Activate the data worksheet */
window -a %(CVWorksheet.getpage()$);

/* Finds the start of the search area for the minimum */
loop(ii,cycle$(y-1),halfcycle$(y))
{
if (%(filename$)_Potential[ii] > 0.3) {break;}
};
maxsearchstart$(y)=ii;

/* Finds the end of the search area for the minimum */
loop(ii,maxsearchstart$(y),halfcycle$(y))
{
if (%(filename$)_Potential[ii] > 0.6) {break;}
};
maxsearchstop$(y)=ii;

/* Writes the values into the search column */
loop (ii, maxsearchstart$(y), maxsearchstop$(y))
{
cell(ii,$(6*$(y)))=cell(ii,$(4+(6*$(y))));
};

/* Find the maximum data value between 0.3V and 0.6V and write it into maxvalue */
stats -s ix:=col($($(y)*6)[$(maxsearchstart$(y)):$(maxsearchstop$(y))]) max:= maxvalueA$(y);

/* Statement to determine the row number where the maximum was found */
loop(ii,$(maxsearchstart$(y)),$(maxsearchstop$(y)))
{
if (%(filename$)_SmoothY$(y)[ii] == maxvalueA$(y)) {break;}
};
intstopA$(y) = ii;

/* Calculate average over 9 points with intstop in middle */
startA$(y) = intstopA$(y) - 5;
addvalA$(y) = 0;
loop(p,1,9)
{
addvalA$(y) += cell((startA$(y)+$(p)),4);
};
baselinevalueA$(y) = (addvalA$(y))/9;

/* Start the anodic integration where the cathodic hydrogen oxidation peak was found */
PotintstartA$(y) = cell(intstopC$(y),1);

/* Loop to determine where the anodic scan has the same voltage */
loop(ii, cycle$(y-1), maxsearchstart$(y))
{
if(%(filename$)_Potential[ii] < PotintstartA$(y)+0.0005 && %(filename$)_Potential[ii] > PotintstartA$(y)-0.0005) {break;}
};
intstartA$(y) = ii;
if($(intstartA$(y)) == $(maxsearchstart$(y)+1))
{
intstartA$(y) = $(cycle$(y-1));
};

/* Statement to put the Current Density numbers into a column to plot just those values being integrated */
loop (ii, intstartA$(y), intstopA$(y))
{
cell(ii,$(1+(6*y)))=cell(ii,4);
};

/* Write baseline values into column over the integration area */
loop (ii, intstartA$(y), intstopA$(y))
{
cell(ii,$(2+(6*y)))=baselinevalueA$(y);
};

/* Code to write the integration baseline and integration curve into range variables */
@global=1;
range rA$(y)b = [%(filename$)]1!$(2+(6*y))[$(intstartA$(y)):$(intstopA$(y))];
range rA$(y)i = [%(filename$)]1!$(1+(6*y))[$(intstartA$(y)):$(intstopA$(y))];
dataset dsAy = rA$(y)i - rA$(y)b;
dataset dsAx = col(Potential);
@global=0;

/* Integrate using the baseline */
integ1 iy:=(dsAx,dsAy) type:=math oy:=<none> area:=Aarea;

/* Write Area into variable */
intareaA$(y)=Aarea;

/* Activate "%(filename$)-integration" */
window -a %(filename$)-Integration$(y);

/* Pause for the cause */
sec -p 0.1;

/* Add Search area to the graph */
plotxy -s iy:=[%(filename$)]!(1,$(6*$(y))[$(maxsearchstart$(y)):$(maxsearchstop$(y))]) plot:=200 legend:=0 ogl:=1;

/* Add Integration area to the graph */
plotxy -s iy:=[%(filename$)]!(1,$(($(y)*6)+1)[$(intstartA$(y)):$(intstopA$(y))]) plot:=200 legend:=0 ogl:=1;

/* Add baseline to graph */
plotxy -s iy:=[%(filename$)]!(1,$(($(y)*6)+2)[$(intstartA$(y)):$(ptendA$(y))]) plot:=200 legend:=0 ogl:=1;

/* */
chargeA$(y)=-((intareaA$(y)*%N)/$(scanrate));

/* */
NptA$(y)=chargeA$(y)/(1.60217733E-19);

/* */
M2GA$(y)=(chargeA$(y)*100000)/($(equationconst)*%N*$(elecload));

/* */
RFA$(y) = $(chargeA$(y))/$(%N)*1000000/$(equationconst);

/* Add label with area to plot */
label -d 1300 875 -s \b(H\-(des) ECA charge [C] = $(chargeA$(y), .5));
label -d 1300 1025 -s \b(H\-(des) Pt ECA [mē/g] = $(M2GA$(y), .5));

/* Clean up the final plot */
layer.X.from = 0.0;

/* Run the embedded table section */
run.section(,EmbeddedTable, $(y));

/* Pause for the cause */
sec -p 0.1;

The part which isn't working is the dataset declaration dataset dsAy = rA$(y)i - rA$(y)b;

It declares on every iteration except the last one.

Hopefully the code will help.

Thanks again for the help!
Patrick
greg Posted - 03/09/2012 : 4:37:45 PM
Again: no code - few ideas.

Are you using any X-Functions within the loop? Particularly as the last statement in the loop? Or creating complex graphs or doing anything very time-consuming?
In those cases, it can help to insert a delay as the last line in the loop, as in:
second -p .5;
which inserts a half second delay.
LabTalk user Posted - 03/02/2012 : 5:01:02 PM
Greg, thanks for the input.

I forced global scope on the datasets so I could see what they were outside of the loop. It is a weird error because it only occurs on the last iteration of the loop, every previous cycle is great. I also ran the code with only one loop cycle and it worked fine. I run an almost identical analysis on a separate section of the data and that code works fine with no errors.

Any ideas/help would be appreciated.

Thanks,
Patrick
greg Posted - 03/01/2012 : 11:14:43 AM
Without seeing the problem it is hard to say what the solution is.
Two things to try:
Use Code Builder to debug and step though your code.
Declare all datasets outside the loop. They will then still be available for testing when exiting the loop.

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000