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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Loop to modify multiple worksheets gets slow
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

andreas1

Germany
12 Posts

Posted - 07/16/2001 :  09:32:05 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

sometimes I like to do the same modifications in all worksheets. When I do this in a loop over all worksheets the loop gets slower and slower for each worksheet and eventually results in a hangup.
Attached is a script that adds columns with the maximum values of selected columns to each worksheet. It works fine for a small number of worksheets (say less 10) but dies for a large number (say > 50). Is there any way to avoid this ?


Thanks,

Andreas



// Add maximum value columns to each worksheet
// Worksheets have responses in X, Y, and Z directions for
// different measurement points (e.g. colA(X) = Frequency,
// colB1(Y)-colB4(Y) Responses in X
// colB5(Y)-colB8(Y) Responses in Y
// colB9(Y)-colB12(Y) Responses in Z
// There can be up to 20 responses in each direction
// At the end of the WS three columns EnvX, EnvY, and EnvZ are
// added. Each containing the maximum of the responses in X, Y, and
// Z respectively.


// Get all worksheets in project
doc -cw;
%Z="";
doc -e W {%Z=%Z %H;};

// Datasets to delete in StatRow worksheet
%O=Row Mean sd se Min Max Range Sum N

// Loop over all worksheets
loop(ii,1,count){
sec;
// Make ii-th worksheet active
%M=%[%Z,#ii];
win -a %M ;
type "Processing %M";
ncol=(wks.nCols - 1) / 3;
// Add columns
wks.addCol(EnvX);
wks.addCol(EnvY);
wks.addCol(EnvZ);
// Select columns with X-responses
loop(jj,2,ncol+1){wks.colSel(jj,1)};
// Get maximum of these columns using StatRow
run.section(WKS,StatRow);
%N=%H;
copy %N_max %M_EnvX;
// Delete StatRow worksheet and datasets (is that the way to do it ??)
win -c %N;
loop(jj,1,9){del %N_%[%O,#ii];};
win -a %M ;
// Select columns with Y-responses
loop(jj,2,ncol+1){wks.colSel(jj,0)};
loop(jj,ncol+2,2*ncol+1){wks.colSel(jj,1)};
// Get maximum of these columns using StatRow
run.section(WKS,StatRow);
%N=%H;
copy %N_max %M_EnvY;
// Delete StatRow worksheet and datasets (is that the way to do it ??)
win -c %N;
loop(jj,1,9){del %N_%[%O,#ii];};
win -a %M ;
// Select columns with Z-responses
loop(jj,ncol+2,2*ncol+1){wks.colSel(jj,0)};
loop(jj,2*ncol+2,3*ncol+1){wks.colSel(jj,1)};
// Get maximum of these columns using StatRow
run.section(WKS,StatRow);
%N=%H;
copy %N_max %M_EnvZ;
// Delete StatRow worksheet and datasets (is that the way to do it ??)
win -c %N;
loop(jj,1,9){del %N_%[%O,#ii];};
win -a %M;
// Hide ii-th worksheet
win -ch 1;
sec -e time;
type (Elapsed time = $(time) sec);
}


Mike Buess

USA
3037 Posts

Posted - 07/16/2001 :  10:56:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I see two errors in your script:
  • // Datasets to delete in StatRow worksheet
    %O=Row Mean sd se Min Max Range Sum N
    (semicolon is missing at end of line)
  • // Delete StatRow worksheet and datasets (is that the way to do it ??)
    win -c %N;
    loop(jj,1,9){del %N_%[%O,#ii];};
    (wrong indices are used in the loop script - should be %N_%[%O,#jj];)
I suspect that the second error is slowing things down. Run the scripts and then enter 'list s' (list data sets) in the script window. You'll probably see that most of the data sets that you wanted to delete are still there and using up local memory.

By the way, if you are using Origin 6.1 you can delete a worksheet and all of its columns with the command 'win -cd wksname'.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 07/16/2001 11:06:26
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000