// These macros demonstrate how to save 
// and open image sequences.

//var path="C:\\WINDOWS\\Desktop\\"; // PC Users 
var path = "/Users/wayne/Desktop/"; // Mac OS X users

macro 'Test Open' {
    newImage("Untitled", "8-bit", 400, 400, 1);
    n=getNumber("Number of Images",3);
    for(i=1; i<=n; i++)
        saveAs("Jpeg", path+"test"+i+".jpg");
    run("Close");
    for(i=1; i<=n; i++) {
        open(path+"test"+i+".jpg");
        wait(2000);
        run("Close");
    }
}

macro 'Test Open Using leftPad()' {
    requires("1.29o");
    newImage("Untitled", "8-bit", 400, 400, 1);
    n=getNumber("Number of Images",3);
    for(i=1; i<=n; i++)
        saveAs("Jpeg", path+"test"+leftPad(i,4)+".jpg");
    run("Close");
    for(i=1; i<=n; i++) {
        open(path+"test"+leftPad(i,4)+".jpg");
        wait(2000);
        run("Close");
    }
}

function leftPad(n, width) {
    s =""+n;
    while (lengthOf(s)<width)
        s = "0"+s;
    return s;
}

macro 'Test leftPad()' {
    for(i=0; i<=1200; i+=100)
        print("file"+leftPad(i, 5)+".tif");
}

