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
 Loop to modify multiple worksheets gets slow

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
andreas1 Posted - 07/16/2001 : 09:32:05 AM
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);
}


1   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 07/16/2001 : 10:56:01 AM
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

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