//AVI to Hyperstack macro //July 5, 2020 //Jeff Hardin, Univ. of Wiscomsin-Madison //Imports AVI file into a virtual HyperStack. Allows legacy 4d footage to //be imported into 64-bit systems now that QuickTime for Jana is deprecated. path = File.openDialog("Select a File"); //print("Path:", path); //open(path); // open the file dir = File.getParent(path); name = File.getName(path); //tries to retrieve an info file. Older ones had the name ",info"; newer ones had ".txt". infoPath = substring(path,0,lastIndexOf(path,".")) + ".info"; textPath = substring(path,0,lastIndexOf(path,".")) + ".txt"; myPath = ""; if (File.exists(infoPath)) {myPath = infoPath;} else if (File.exists(textPath)) {myPath = textPath;} //print("My path: ", myPath); focalPlanes = 1; if (myPath != "") { //print("Found focal planes:"); infoString = File.openAsString(myPath); // open the file lines=split(infoString,"\n"); //print(lines[1]); movieInfo = lines[0]; //The info files is sensitive to leading spaces in the focal plane line, //which I believe is due to the macro language. focalPlanes = parseInt(lines[1]); //print("Focal planes: ", focalPlanes); } else //if no info file with the approporatie root can be found, ask for focal planes { Dialog.create("Enter focal planes"); Dialog.addNumber("Couldn't get focal planes. Focal planes: ", 1); Dialog.show(); focalPlanes = Dialog.getNumber();; if (focalPlanes < 1) {focalPlanes = 1;} movieInfo = ""; } //list = getFileList(dir); //print("Directory contains "+list.length+" files"); run("AVI...", "open=[" + path + "] use convert"); //get total images, contained in the slices field in next line getDimensions(w, h, channels, slices, frames); //print("Total images: " + slices); //now get time points timePoints = slices/focalPlanes; //print("Time points: ",timePoints); String.show("Movie info", "Movie info:\n" + movieInfo + "\n" + "\n" + "Focal planes: " + focalPlanes + "\nTime points: " + timePoints); run("Stack to Hyperstack...","order=xyctz channels=1 slices=" + focalPlanes + " frames=" + timePoints + " display=Grayscale");