Macro Language | Fast array filtering

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Macro Language | Fast array filtering

Rainer M. Engel
Hello everyone,

I came across another way to enhance the speed of a macro in case one
wants to filter for certain files in a directory.

1.) You may want to open a dir (i.e. recursive if you like). The result
would be an array of files called "list1".

2.) The macro below speeded up my script by a magnitude compared to
Array.concat oder string appending concepts.


//Clean list1 to retrieve only actual workfiles
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
list2 = Array.copy(list1); //copy list1
listC = 0; //listCounter for found elements
for (i=0; i<list1.length; i++) {
        showProgress(i/list1.length);
        if (matches(list1[i], ".*.tif")) { //condition to filter by
                list2[listC] = list1[i];
                listC++;
        }
}
list2 = Array.trim(list2, listC);
print("File(s) found: "+list1.length+", "+list2.length+" to work on..");
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Maybe some of you find this usefull.

Best Regards,
Rainer


--
Rainer M. Engel, Dipl. Digital Artist

endime|ENGEL DIGITAL MEDIA
Pichelsdorferstr. 143
D-13595 Berlin

Tel: +49 (0)30-922 52 0 96
Mob: +49 (0)174-3355549

Web:    www.endime.de
E-Mail: [hidden email]

USt.Id: DE254256305

BANK:   Triodos Bank Deutschland
Kto:    1037 0110 09
BLZ:    5003 1000
IBAN:   DE15 5003 1000 1037 0110 09
BIC:    TRODDEF1XXX


Hinweis / Notice:
Der Inhalt dieser E-Mail ist vertraulich und ausschließlich fuer den
bezeichneten Adressaten bestimmt.
Wenn Sie nicht der vorgesehene Adressat dieser E-Mail oder dessen
Vertreter sein sollten, so beachten
Sie bitte, dass jede Form der Kenntnisnahme, Veroeffentlichung,
Vervielfaeltigung oder Weitergabe des
Inhalts dieser E-Mail unzulaessig ist. Wir bitten Sie, sich in diesem
Fall mit dem Absender der E-Mail in
Verbindung zu setzen.

The information contained in this email is confidential and intended
solely for the addressee. Access to
this email by anyone else is unauthorized. If you are not the intended
recipient, any form of disclosure,
reproduction, distribution or any action taken or refrained from in
reliance on it, is prohibited and may
be unlawful. Please notify the sender immediately.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html